Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   A drive letter is related to which physical disk?! (https://forum.exetools.com/showthread.php?t=11226)

just4urim 10-24-2007 19:30

A drive letter is related to which physical disk?!
 
Hi all ,

I'm really interested if there's a way to find out that a specific drive letter is related to which physical disk? ( in XP and 98 ) . however in XP I found an IOCTL code ( IOCTL_DISK_GET_DRIVE_LETTERS ) , but it has not been even defined in windows! and i can't to compile my application!

Any idea? Is there any way ? ( for example from kernel mode ).

Tnx,
Just4uriM

evlncrn8 10-24-2007 22:08

mountmgr.....

JuneMouse 10-25-2007 01:12

you dont need r0 to get all these information

simply start wmic in cmd.exe

and get all the information you need

Code:

wmic:root\cli>path Win32_DiskPartition get Deviceid
DeviceID
Disk #0, Partition #0
Disk #0, Partition #1
Disk #0, Partition #2
Disk #2, Partition #0

wmic:root\cli>path Win32_logicaldisk get Deviceid
DeviceID
A:
C:
D:
E:
G:

wmic:root\cli>path Win32_diskdrive get Deviceid
DeviceID
\\.\PHYSICALDRIVE0
\\.\PHYSICALDRIVE2

wmic:root\cli>

try this command for an amazing amount of information about your diskdrives inside wmic
Code:

path Win32_DiskPartition assoc
or you can code a few lines in the latest leet language c#

or script oldstyle

Code:

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 & ")"

    'Use the disk drive device id to
    ' find associated partition
    query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
        & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"   
    Set wmiDiskPartitions = wmiServices.ExecQuery(query)

    For Each wmiDiskPartition In wmiDiskPartitions
        'Use partition device id to find logical 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

output as follows for above script

wmic:/>cscript foo.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Disk drive Caption: ************
DeviceID:  (\\.\PHYSICALDRIVE0)
Drive letter associated with disk drive = ***********\\.\PHYSICALDRIVE0
 Partition = Disk #0, Partition #0
 is C:
Drive letter associated with disk drive = **********\\.\PHYSICALDRIVE0
 Partition = Disk #0, Partition #1
 is E:
Drive letter associated with disk drive = **********\\.\PHYSICALDRIVE0
 Partition = Disk #0, Partition #2
 is D:
Disk drive Caption: *********** USB Device
DeviceID:  (\\.\PHYSICALDRIVE2)
Drive letter associated with disk drive = *********** USB Device\\.\PHYSI
CALDRIVE2
 Partition = Disk #2, Partition #0
 is G:

wmic:/>

above script is from ms
http://msdn2.microsoft.com/en-us/library/aa394592.aspx

Quote:

...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.

just4urim 11-05-2007 15:16

Thanks for your guidance,
Quote:

Originally Posted by JuneMouse
you dont need r0 to get all these information

simply start wmic in cmd.exe

and ...

actually i did it in other way ;) and as writing a Client Mount Manager was a bit vague! , I prefered to explore for some thing else . I used a smart IOCTL IOCTL_VOLUME_LOGICAL_TO_PHYSICAL to find the related physical hard disk number for a logical drive . May be it would help you in some way! ;)

Regards,
Just4UriM


All times are GMT +8. The time now is 04:51.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX