阅读:2287回复:6
2k下如何根据盘符得到其所属的硬盘
比如有个盘符x:,如何得到它在哪块硬盘?
xp下可以用IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, 2k下怎么办?? |
|
沙发#
发布于:2005-05-17 13:14
FileHandle = ZwCreateFile(\"\\\\??\\\\x:\",.....);
ObReferenceObjectByHandle(.....); IoGetRelatedDeviceObject(...); it\'s ok now! |
|
板凳#
发布于:2005-05-18 14:49
我是想得到硬盘编号,就是xp下用ioctl_volume_get_volume_disk_extends得到的DiskNumber
|
|
驱动老牛
|
地板#
发布于:2005-05-19 09:25
我是想得到硬盘编号,就是xp下用ioctl_volume_get_volume_disk_extends得到的DiskNumber 哦 这个呀,WMI可以做到 而且很容易 MSDN上有示例。 |
|
地下室#
发布于:2005-05-19 10:58
[quote]我是想得到硬盘编号,就是xp下用ioctl_volume_get_volume_disk_extends得到的DiskNumber 哦 这个呀,WMI可以做到 而且很容易 MSDN上有示例。 [/quote] wmi我不熟,能讲得详细些吗,谢谢 [编辑 - 5/19/05 by tooflat] |
|
驱动老牛
|
5楼#
发布于:2005-05-19 13:21
[quote][quote]我是想得到硬盘编号,就是xp下用ioctl_volume_get_volume_disk_extends得到的DiskNumber 哦 这个呀,WMI可以做到 而且很容易 MSDN上有示例。 [/quote] wmi我不熟,能讲得详细些吗,谢谢 [编辑 - 5/19/05 by tooflat] [/quote] 就向COM一样 MSDN里有例子 用 Win32_DiskDriveToDiskPartition 等类就行了。 就象这样使用 strComputer = \".\" Set objWMIService = GetObject(\"winmgmts:\" _ & \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\") Set colDisks = objWMIService.ExecQuery _ (\"Select * from Win32_LogicalDisk\") For Each objDisk in colDisks Wscript.Echo \"DeviceID: \"& vbTab & objDisk.DeviceID Wscript.Echo \"File System: \"& vbTab & objDisk.FileSystem Next |
|
驱动老牛
|
6楼#
发布于:2005-05-19 13:22
...detect which drive letter is associated with a logical disk partition? Start with the Win32_DiskDrive class and query for instances of Win32_DiskPartition using the DeviceID property and the Win32_DiskDriveToDiskPartition association class. Now you have a collection of the partitions on the physical drive.
Query for the Win32_LogicalDisk that represents the partition using the Win32_DiskPartition.DeviceID property and Win32_LogicalDiskToPartition association class. Get the drive letter from the Win32_LogicalDisk.DeviceID. ComputerName = \".\" Set wmiServices = GetObject (\"winmgmts:{impersonationLevel=Impersonate}!//\" & ComputerName) \' Get physical disk drive Set wmiDiskDrives = wmiServices.ExecQuery (\"SELECT Caption, DeviceID FROM Win32_DiskDrive\") For Each wmiDiskDrive In wmiDiskDrives WScript.Echo \"Disk drive Caption: \" & wmiDiskDrive.Caption _ & VbNewLine & \"DeviceID: \" & \" (\" & wmiDiskDrive.DeviceID & \")\" \'Backslash in disk drive deviceid must be escaped by \"\\\" strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, \"\\\", \"\\\\\", 1, -1, vbTextCompare) \'Use the disk drive device id to find associated partition Set wmiDiskPartitions = wmiServices.ExecQuery_ (\"ASSOCIATORS OF {Win32_DiskDrive.DeviceID=\"\"\" _ & strEscapedDeviceID & \"\"\"} WHERE _ AssocClass = Win32_DiskDriveToDiskPartition\") For Each wmiDiskPartition In wmiDiskPartitions \'Use partition device id to find locial disk Set wmiLogicalDisks = wmiServices.ExecQuery _ (\"ASSOCIATORS OF {Win32_DiskPartition.DeviceID=\"\"\" & _ wmiDiskPartition.DeviceID & \"\"\"} WHERE _ AssocClass = Win32_LogicalDiskToPartition\") For Each wmiLogicalDisk In wmiLogicalDisks WScript.Echo \"Drive letter associated with disk drive = \" & wmiDiskDrive.Caption & wmiDiskDrive.DeviceID _ & VbNewLine & \" Partition = \" & wmiDiskPartition.DeviceID _ & VbNewLine & \" is \" & wmiLogicalDisk.DeviceID Next Next Next |
|