Sign in to follow this  
Followers 0
tkocsir

How to get drive letter from \Device\HarddiskVolumeX ?

8 posts in this topic

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

Share this post


Link to post
Share on other sites



See this ProgAndy post, it can help you Posted Image

I found this post earlier and started to play around with those scripts, but I couldn't manage to create anything useful.;)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#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
1 person likes this

Share this post


Link to post
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...

Share this post


Link to post
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
Sign in to follow this  
Followers 0