感谢您使用微软产品。你可以使用WMI的Win32_LogicalDisk对象获得逻辑盘的各项信息,如下例:Private Sub Command1_Click()WQL = "Select * From Win32_LogicalDisk" Set LDisks = GetObject("winmgmts:").ExecQuery(WQL)For Each disk In LDisks Debug.Print disk.Name Debug.Print disk.VolumeName NextEnd Sub你可以使用WMI的Win32_DiskPartition对象获得硬盘分区的各项信息,其中DiskIndex属性可用于区分属于哪一个硬盘,如下例:Private Sub Command2_Click() WQL = "Select * From Win32_DiskPartition"Set PDisks = GetObject("winmgmts:").ExecQuery(WQL) For Each disk In PDisks Debug.Print disk.Name Debug.Print disk.Index Debug.Print disk.DiskIndex Next End Sub从逻辑盘符获得该逻辑盘所在分区,从而获得所在硬盘的Index,就能判断两个逻辑盘是否属于同一个物理盘。您可以用WQL的Associators OF关键字关联win32_LogicalDisk和Win32_DiskPartition,实现上述查询,如下例:Private Sub Command3_Click()WQL = "Associators of {win32_LogicalDisk='C:'} where resultClass = Win32_DiskPartition"Set Pattions = GetObject("winmgmts:").ExecQuery(WQL)For Each Pat In Pattions Debug.Print Pat.Name Debug.Print Pat.DiskIndex NextEnd Sub详细信息请参考: Win32_LogicalDisk http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp Win32_DiskPartition http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_diskpartition.asp ASSOCIATORS OF Statement http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/associators_of_statement.asp - 微软全球技术中心 VB技术支持本帖子仅供SINA的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。 为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,23094245))。 ======================
我再研究,得出下面的代码: 把它保存为.vbs文件就可以运行了。ComputerName = "." Set wmiServices = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName) Set wmiDiskDrives = wmiServices.ExecQuery ("SELECT Caption, DeviceID FROM Win32_DiskDrive")For Each wmiDiskDrive In wmiDiskDrives WScript.Echo wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")" strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare) Set wmiDiskPartitions = wmiServices.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _ strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For Each wmiDiskPartition In wmiDiskPartitions WScript.Echo vbTab & wmiDiskPartition.DeviceID Set wmiLogicalDisks = wmiServices.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _ wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition") For Each wmiLogicalDisk In wmiLogicalDisks WScript.Echo vbTab & vbTab & wmiLogicalDisk.DeviceID Next Next Next
我寄给你的邮件被退了回来,主页又上不了,5555555555~~~~~~~~~~ ,3tx 3tx 3tx very much!!
楼主用的是VB.NET吧,我试过,可以呀!Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As IntegerPrivate Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)Private Const MOUSEEVENTF_LEFTDOWN As Short = &H2S Private Const MOUSEEVENTF_LEFTUP As Short = &H4S Private Const MOUSEEVENTF_RIGHTDOWN As Short = &H8S Private Const MOUSEEVENTF_RIGHTUP As Short = &H10SPrivate Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click SetCursorPos(50, 100) mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0) Sleep (10) mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)End Sub他是模拟在桌面上(50,100)点击鼠标右键。
刚才贴错帖了,呵呵。我用WMI来实现了这个问题:Private Sub Command1_Click()
Dim ComputerName As String Dim wmiServices As Object Dim wmiDiskDrives As Object Dim wmiDiskDrive As Object
Dim wmiDiskPartitions As Object Dim wmiDiskPartition As Object Dim strEscapedDeviceID As String
ComputerName = "." Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName) Set wmiDiskDrives = wmiServices.ExecQuery("SELECT Caption, DeviceID FROM Win32_DiskDrive")
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare) Set wmiDiskPartitions = wmiServices.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _ strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
'// Debug.Print "2|" & vbTab & wmiDiskPartition.DeviceID Set wmiLogicalDisks = wmiServices.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _ wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition") For Each wmiLogicalDisk In wmiLogicalDisks '// Debug.Print "3|" & vbTab & vbTab & wmiLogicalDisk.DeviceID Next Next NextEnd Sub
而真正起作用的程序是mmc.exe(控制台),我看了一下它的DLL导入,除了MFC42U.Dll和MSVCP50.DLL以及ATL.DLL比较特别外,其他都用的标准API,至于msc本身的特性,倒是不清楚了,不过多少是个方向
在Win NT/2000/XP下, 可以用下面的方法(nHD从0开始):
void GetHDPartition(int nHD)
{
char buf0[33];
char buf1[128];
char buf2[2048];
DWORD dwNum;
HANDLE hDevice;
PARTITION_INFORMATION pi;
DRIVE_LAYOUT_INFORMATION* pdli; wsprintf(buf0, "\\\\.\\PHYSICALDRIVE%d", nHD);
hDevice = CreateFile(buf0, GENERIC_READ, 0,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice==(HANDLE)-1) {
ShowMessage(SysErrorMessage(GetLastError()));
return;
}
pdli = (DRIVE_LAYOUT_INFORMATION*)buf2;
memset(buf2, 0, sizeof(buf2));
DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT,
NULL, 0, buf2, sizeof(buf2), &dwNum, NULL);
CloseHandle(hDevice); GetLogicalDriveStrings(sizeof(buf1), buf1);
for(char* s=buf1; *s!=0; s+=strlen(s)+1) {
if (GetDriveType(s)!=DRIVE_FIXED)
continue;
wsprintf(buf0, "\\\\.\\%c:", *s);
hDevice = CreateFile(buf0, GENERIC_READ,
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
0, NULL);
if (hDevice==(HANDLE)-1) continue;
if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO,
NULL, 0, &pi, sizeof(pi), &dwNum, NULL)) {
CloseHandle(hDevice); continue;
}
for(int n=0; n<pdli->PartitionCount; n++) {
if (memcmp(pdli->PartitionEntry+n,&pi,
2*sizeof(LARGE_INTEGER))==0) {
MessageBox(0, s, "是指定硬盘上的一个分区",
MB_OK);
break;
}
}
CloseHandle(hDevice);
}
}上面的代码需要包含头文件 winioctl.h
IOCTL_DISK_GET_DRIVE_LAYOUT=475148
IOCTL_DISK_GET_PARTITION_INFO=475140typedef struct _PARTITION_INFORMATION {
LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength;
DWORD HiddenSectors;
DWORD PartitionNumber;
BYTE PartitionType;
BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition;
BOOLEAN RewritePartition;
}typedef struct _DRIVE_LAYOUT_INFORMATION {
DWORD PartitionCount;
DWORD Signature;
PARTITION_INFORMATION PartitionEntry[1];
}
因为WMI可以用下面的方法查询出一个逻辑盘的归属:如Query:
ASSOCIATORS OF {Win32_LogicalDisk.DeviceID="C:"}
WHERE RequiredAssocQualifier = Association
Results:
Win32_Directory.Name="C:\\"
Win32_ComputerSystem.Name="mycomputer"
Win32_DiskPartition.DeviceID="Disk #0, Partition #0"
只要将 DeviceID="C:" D: E: F:....... 下去就得到一个表格了。
但是在VB了怎样调用WMI以及怎样获取返回的信息呢????上面的两个方法都只能在Win2000/xp下工作,在win98呢?????????5555555
Platform SDK: Windows Management Instrumentation
感谢您使用微软产品。你可以使用WMI的Win32_LogicalDisk对象获得逻辑盘的各项信息,如下例:Private Sub Command1_Click()WQL = "Select * From Win32_LogicalDisk"
Set LDisks = GetObject("winmgmts:").ExecQuery(WQL)For Each disk In LDisks
Debug.Print disk.Name
Debug.Print disk.VolumeName
NextEnd Sub你可以使用WMI的Win32_DiskPartition对象获得硬盘分区的各项信息,其中DiskIndex属性可用于区分属于哪一个硬盘,如下例:Private Sub Command2_Click()
WQL = "Select * From Win32_DiskPartition"Set PDisks = GetObject("winmgmts:").ExecQuery(WQL)
For Each disk In PDisks
Debug.Print disk.Name
Debug.Print disk.Index
Debug.Print disk.DiskIndex
Next
End Sub从逻辑盘符获得该逻辑盘所在分区,从而获得所在硬盘的Index,就能判断两个逻辑盘是否属于同一个物理盘。您可以用WQL的Associators OF关键字关联win32_LogicalDisk和Win32_DiskPartition,实现上述查询,如下例:Private Sub Command3_Click()WQL = "Associators of {win32_LogicalDisk='C:'} where resultClass = Win32_DiskPartition"Set Pattions = GetObject("winmgmts:").ExecQuery(WQL)For Each Pat In Pattions
Debug.Print Pat.Name
Debug.Print Pat.DiskIndex
NextEnd Sub详细信息请参考:
Win32_LogicalDisk
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp
Win32_DiskPartition
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_diskpartition.asp
ASSOCIATORS OF Statement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/associators_of_statement.asp
- 微软全球技术中心 VB技术支持本帖子仅供SINA的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,23094245))。
======================
不知这个对你有用么?
只是来看看
以前我总是希望自己发的贴子能有更多的人光顾
虽然我不能帮你
但已经把你的贴子加入了我的收藏夹
学习
把它保存为.vbs文件就可以运行了。ComputerName = "."
Set wmiServices = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery ("SELECT Caption, DeviceID FROM Win32_DiskDrive")For Each wmiDiskDrive In wmiDiskDrives
WScript.Echo wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For Each wmiDiskPartition In wmiDiskPartitions
WScript.Echo vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
Next
playyuer、foolishtiger、songyangk、zyl910、TechnoFantasy 呢??
提供原代码,实现方法:ATL+VISUAL BASIC
DEVICEIOCONTROL API调用
ROSEMENT.DIY.163.COM
,3tx 3tx 3tx very much!!
Private Const MOUSEEVENTF_LEFTUP As Short = &H4S
Private Const MOUSEEVENTF_RIGHTDOWN As Short = &H8S
Private Const MOUSEEVENTF_RIGHTUP As Short = &H10SPrivate Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click SetCursorPos(50, 100)
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
Sleep (10)
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)End Sub他是模拟在桌面上(50,100)点击鼠标右键。
Dim ComputerName As String
Dim wmiServices As Object
Dim wmiDiskDrives As Object
Dim wmiDiskDrive As Object
Dim wmiDiskPartitions As Object
Dim wmiDiskPartition As Object
Dim strEscapedDeviceID As String
ComputerName = "."
Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery("SELECT Caption, DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
'//
Debug.Print "1|" & wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
'//
Debug.Print "2|" & vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
'//
Debug.Print "3|" & vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
NextEnd Sub