Jump to content

How to get drive letter from \Device\HarddiskVolumeX ?


tkocsir
 Share

Recommended Posts

Hi!

I need to detect the drive letter from a string like \Device\HarddiskVolume2, but I don't know how to use the DllCall function with GetVolumeNameForVolumeMountPoint.

For example I write something like this:

$driveletter = DllCall("kernel32.dll","something","GetVolumeNameForVolumeMountPoint",...some stuff, and \Device\HarddiskVolume2\...)

And then $driveletter would be "C:" or "D:\" or anything.

Can someone write me the right syntax?

Regards,

Thomas

Link to comment
Share on other sites

What you mean "\Device\HarddiskVolume2"?

I need to read paths from the registry and several values contain the path as:

\Device\HarddiskVolume2\Program Files\SomeProgram\exe.exe

And I need to do different hashes (MD5, SHA-1) for the file, but this is not an acceptable path form for the function. (I am using this: hash udf)

Edited by tkocsir
Link to comment
Share on other sites

You can use WMI and its class Win32_Volume to get the volumes and the appropriate drive letters but it displays only DeviceIDs and not e.g. \Device\HarddiskVolume2\.

Maybe somebody knows how to get the desired name from the DeviceID...

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

#Include <WinAPIEx.au3>

ConsoleWrite(_DosPathNameToPathName('\Device\HarddiskVolume2\Program Files\SomeProgram\exe.exe') & @CR)

Func _DosPathNameToPathName($sPath)

    Local $sName, $aDrive = DriveGetDrive('ALL')

    If Not IsArray($aDrive) Then
        Return SetError(1, 0, $sPath)
    EndIf

    For $i = 1 To $aDrive[0]
        $sName = _WinAPI_QueryDosDevice($aDrive[$i])
        If StringInStr($sPath, $sName) = 1 Then
            Return StringReplace($sPath, $sName, StringUpper($aDrive[$i]), 1)
        EndIf
    Next
    Return SetError(2, 0, $sPath)
EndFunc   ;==>_DosPathNameToPathName

WinAPIEx.au3

Edited by Yashied
Link to comment
Share on other sites

#Include <WinAPIEx.au3>

ConsoleWrite(_DosPathNameToPathName('\Device\HarddiskVolume2\Program Files\SomeProgram\exe.exe') & @CR)

Func _DosPathNameToPathName($sPath)

    Local $sName, $aDrive = DriveGetDrive('ALL')

    If Not IsArray($aDrive) Then
        Return SetError(1, 0, $sPath)
    EndIf

    For $i = 1 To $aDrive[0]
        $sName = _WinAPI_QueryDosDevice($aDrive[$i])
        If StringInStr($sPath, $sName) = 1 Then
            Return StringReplace($sPath, $sName, StringUpper($aDrive[$i]), 1)
        EndIf
    Next
    Return SetError(2, 0, $sPath)
EndFunc   ;==>_DosPathNameToPathName

WinAPIEx.au3

Thank you very much Yashied, it works! ;)

*facepalm* that I didn't find this function in WinAPIEx...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...