Jochem Posted April 27, 2010 Share Posted April 27, 2010 (edited) does anybody have an idea to resolve the guid of a specific drive without having an drive letter? I am now using this script Func _cddrives() $acddrives = DriveGetDrive("CDROM") If @error Then _remdrives() Else For $scddrive In $acddrives $scddrivetxt = StringTrimRight($scddrive, 1) RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $scddrive & " /L >c:\temp\" & $scddrivetxt & ".txt", "", @SW_HIDE) Next For $scddrive In $acddrives RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $scddrive & " /D", "", @SW_HIDE) Next For $scddrive In $acddrives $CDascistart = $CDascistart + 1 $cddriveletter = Chr($CDascistart) $scddrivetxt = StringTrimRight($scddrive, 1) $cdvolguid = FileReadLine("c:\temp\" & $scddrivetxt & ".txt", 1) RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $cddriveletter & ":" & $cdvolguid, "", @SW_HIDE) FileDelete("c:\temp\" & $scddrivetxt & ".txt") Next _remdrives() EndIf EndFunc Edited April 27, 2010 by Jochem Link to comment Share on other sites More sharing options...
Fire Posted April 27, 2010 Share Posted April 27, 2010 (edited) Hi. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiEdit.au3> #cs tested on win xp 5.1.2600 Service Pack 2 2600 27.04.2k10 sh3lc043r #ce #Region ### START Koda GUI section ### Form=Form1.kxf $Form1 = GUICreate("", 598, 345, 192, 124) $Edit1 = GUICtrlCreateEdit("", 104, 32, 361, 217) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Get List", 208, 280, 129, 33, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetData($Edit1,"") $i=0 Do $key="HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" $i+=1 $key=RegEnumVal($key,$i) _GUICtrlEdit_AppendText($Edit1,$key & @CRLF) ;MsgBox(64,"",$key) ;works Until $key="" EndSwitch WEnd edit:It gets all guids for all drives. Edited April 27, 2010 by Sh3llC043r [size="5"] [/size] Link to comment Share on other sites More sharing options...
Jochem Posted April 27, 2010 Author Share Posted April 27, 2010 I know that registry key, but than I do I know wich guid is wich drive (cd drive or flashcard reader, etc.) Link to comment Share on other sites More sharing options...
zorphnog Posted April 27, 2010 Share Posted April 27, 2010 Maybe something like this? $aDrives = DriveGetDrive("ALL") For $i=1 To $aDrives[0] ConsoleWrite(StringFormat("%s\\\t%s\r\n", $aDrives[$i], _GetVolumeNameForVolumeMountPoint($aDrives[$i] & "\"))) Next Func _GetVolumeNameForVolumeMountPoint($sMountPoint) Local $tBuffer, $pBuffer, $aCall $tBuffer = DllStructCreate("wchar buffer[256]") $pBuffer = DllStructGetPtr($tBuffer) $aCall = DllCall("kernel32.dll", "bool", "GetVolumeNameForVolumeMountPointW", "wstr", $sMountPoint, "ptr", $pBuffer, "dword", 256) If @error Then ConsoleWrite("! ERROR: " & @error & @CRLF) Return SetError(1, 0, -1) EndIf Return DllStructGetData($tBuffer, 1) EndFunc Link to comment Share on other sites More sharing options...
99ojo Posted April 27, 2010 Share Posted April 27, 2010 (edited) Hi, have a look at the consolewrite output for your further coding: #include <array.au3> Dim $arvol [1] [2] Dim $ardevice [1] [2] ;get cdrom drives $ardrives = DriveGetDrive ("CDROM") $countdev = 0 $countvol = 0 For $i = 1 to 100 ;get all keys $var = RegEnumVal("HKEY_LOCAL_MACHINE\System\MountedDevices", $i) if @error <> 0 Then ExitLoop ;make difference between volumes and dosdevices If StringinStr ($var, "DosDevices") = 0 Then ReDim $arvol [$countvol + 1] [2] $arval [$countvol] [0] = $var $arval [$countvol] [1] = RegRead ("HKEY_LOCAL_MACHINE\System\MountedDevices", $var) $countvol += 1 Else ReDim $ardevice [$countdev + 1] [2] $ardevice [$countdev] [0] = $var $ardevice [$countdev] [1] = RegRead ("HKEY_LOCAL_MACHINE\System\MountedDevices", $var) $countdev += 1 EndIf next ;loop over cdrom drive array For $i = 1 To Ubound ($ardrives) - 1 ;partitial search for drive letter in dosdevice array $indexdev = _ArraySearch ($ardevice, $ardrives [$i], 0, 0, 0, 1) ;compare value from dosdevice array with value in volumearray $indexvol = _ArraySearch ($arvol, $ardevice [$indexdev] [1], 0, 0, 0, 0, 1, 1) ConsoleWrite ($arvol [$indexvol] [0] & " " & $ardevice [$indexdev] [0] & @CRLF) Next ;-)) Stefan @zorphnog: Tried your code and getting errors: ! ERROR: 2 e:\ -1 ! ERROR: 2 h:\ -1 ! ERROR: 2 t:\ -1 ! ERROR: 2 u:\ -1 ! ERROR: 2 v:\ -1 ! ERROR: 2 w:\ -1 ! ERROR: 2 x:\ -1 ! ERROR: 2 y:\ -1 Edited April 27, 2010 by 99ojo Link to comment Share on other sites More sharing options...
Jochem Posted April 27, 2010 Author Share Posted April 27, 2010 cool script, but maybe my question was not clearly formulated. The problem I have is that the cd drives are unmounted, so I cannot resolve the quid by drive letter. and I need to remount them Link to comment Share on other sites More sharing options...
zorphnog Posted April 27, 2010 Share Posted April 27, 2010 (edited) @zorphnog: Tried your code and getting errors: I think you might be using an older version of AutoIt. Try changing "bool" to "int". Here's an example going from volume path name to volume name. $i = 1 While 1 $sValue = RegEnumVal("HKLM\System\MountedDevices", $i) If @error Then ExitLoop If StringRegExp($sValue, "(?i)\\\?\?\\Volume{[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}", 0) Then $sValue = StringReplace($sValue, "\??\", "\\?\") ConsoleWrite(StringFormat("%s\t%s\r\n", _GetVolumePathNamesForVolumeName($sValue & "\"), $sValue & "\")) EndIf $i += 1 WEnd Func _GetVolumePathNamesForVolumeName($sVolumeName) Local $tData, $pBuffer, $pSize $tData = DllStructCreate("dword size;wchar buffer[256]") $pBuffer = DllStructGetPtr($tData, "buffer") $pSize = DllStructGetPtr($tData, "size") $aCall = DllCall("kernel32.dll", "int", "GetVolumePathNamesForVolumeNameW", "wstr", $sVolumeName, "ptr", $pBuffer, "dword", 256, "ptr", $pSize) If @error Then ConsoleWrite("! ERROR: " & @error & @CRLF) Return SetError(1, 0, -1) EndIf Return DllStructGetData($tData, "buffer") EndFunc ;==>_GetVolumePathNamesForVolumeName Edit: Didn't see your latest post @Jochem. I'm not sure that you can determine the type if it is not associated with a drive letter. Edited April 27, 2010 by zorphnog Link to comment Share on other sites More sharing options...
99ojo Posted April 27, 2010 Share Posted April 27, 2010 (edited) Hi, change bool to int and works now. The output are the same as mine with the regread version. But still Jochem has the problem the other way round. He wants the unmounted Volumes -> this isn't the problem changed for...loop For $i = 0 To Ubound ($arvol) - 1 $indexdev = _ArraySearch ($ardevice, $arvol [$i] [1], 0, 0, 0, 0, 1, 1) If $indexdev < 1 Then ConsoleWrite ($arvol [$i] [0] & " not mounted" & @CRLF) Else ConsoleWrite ($arvol [$i] [0] & " mounted as " & $ardevice [$indexdev] [0] & @CRLF) EndIf Next ??? But how can he / we identify, that the unmounted volume is / was a cd-rom volume ??? ;-(( Stefan @Edit: Older version -> yes: 3.3.0.0 I'm not sure that you can determine the type if it is not associated with a drive letter. Jochem, that's the problem... Edited April 27, 2010 by 99ojo Link to comment Share on other sites More sharing options...
zorphnog Posted April 27, 2010 Share Posted April 27, 2010 You can use the DriveGetType on volume path names. $i = 1 While 1 $sValue = RegEnumVal("HKLM\System\MountedDevices", $i) If @error Then ExitLoop If StringRegExp($sValue, "(?i)\\\?\?\\Volume{[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}", 0) Then $sValue = StringReplace($sValue, "\??\", "\\?\") $sValue &= "\" ConsoleWrite(StringFormat("%s\t%s\r\n", $sValue, DriveGetType($sValue))) EndIf $i += 1 WEnd Link to comment Share on other sites More sharing options...
99ojo Posted April 27, 2010 Share Posted April 27, 2010 Hi, still the mounted one's.... Stefan Link to comment Share on other sites More sharing options...
Jochem Posted April 27, 2010 Author Share Posted April 27, 2010 (edited) SUPER!!! (for me it also gives also the unmounted devices, I will test it on several computers) Edited April 27, 2010 by Jochem Link to comment Share on other sites More sharing options...
99ojo Posted April 27, 2010 Share Posted April 27, 2010 Hmmm, i guess you are running vista or above. XP SP3 and now AutoIT 3.3.6.1: still gives me only the Drivetypes of the mounted volumes. \\?\Volume{8e1c9182-ebd5-11dd-b369-806d6172696f}\ Removable \\?\Volume{8e1c9183-ebd5-11dd-b369-806d6172696f}\ \\?\Volume{8e1c9184-ebd5-11dd-b369-806d6172696f}\ Fixed \\?\Volume{8e1c9185-ebd5-11dd-b369-806d6172696f}\ \\?\Volume{175a18b0-ebc8-11dd-9897-806d6172696f}\ \\?\Volume{175a18b1-ebc8-11dd-9897-806d6172696f}\ CDROM \\?\Volume{65dcd760-ed63-11dd-98a6-00300596239d}\ \\?\Volume{3f877a8c-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877a8e-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877a8f-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877aa0-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877aa1-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877aa2-ee22-11dd-98a9-00300596239d}\ \\?\Volume{3f877aa3-ee22-11dd-98a9-00300596239d}\ \\?\Volume{8d9fe04a-eed0-11dd-98ac-00300596239d}\ \\?\Volume{26ffc284-f086-11dd-98b6-00300596239d}\ \\?\Volume{26ffc285-f086-11dd-98b6-00300596239d}\ \\?\Volume{ef2d91b8-f514-11dd-98c4-00e07d7a11da}\ Fixed \\?\Volume{ef2d91ba-f514-11dd-98c4-00e07d7a11da}\ Fixed \\?\Volume{b575fee6-f61e-11dd-9b93-806d6172696f}\ CDROM \\?\Volume{b575fee7-f61e-11dd-9b93-806d6172696f}\ CDROM \\?\Volume{b575fee8-f61e-11dd-9b93-806d6172696f}\ CDROM \\?\Volume{b575fee9-f61e-11dd-9b93-806d6172696f}\ CDROM \\?\Volume{54a5955e-0582-11de-9bc2-001e2acfff3f}\ \\?\Volume{0c307f58-1c68-11de-9d19-806d6172696f}\ \\?\Volume{fc44196a-566e-11de-9d65-001e2acfff3f}\ \\?\Volume{416763b2-692a-11de-82e3-806d6172696f}\ CDROM \\?\Volume{c40c169e-a3a6-11de-833f-001e2acfff3f}\ \\?\Volume{c40c169f-a3a6-11de-833f-001e2acfff3f}\ CDROM \\?\Volume{0221bec8-c3ed-11de-8379-001e2acfff3f}\ \\?\Volume{81249cc4-febf-11de-83ee-001e2acfff3f}\ \\?\Volume{81249cc5-febf-11de-83ee-001e2acfff3f}\ \\?\Volume{babb31d8-fd5b-11de-8415-001e2acfff3f}\ \\?\Volume{e4a34b24-10df-11df-8450-001e2acfff3f}\ CDROM \\?\Volume{816d30d8-35ec-11df-84e6-001e2acfff3f}\ It would be nice to know, if this is OS specific, or did i missed something? ;-)) Stefan Link to comment Share on other sites More sharing options...
Jochem Posted April 27, 2010 Author Share Posted April 27, 2010 indeed for usb-sticks is doesnt work, but on windows 7 it works for the CDROM and for the Cardreaders.... hope it is working on xp sp3 too..... Link to comment Share on other sites More sharing options...
Fire Posted April 27, 2010 Share Posted April 27, 2010 (edited) zorphnogYou can use the DriveGetType on volume path names.Really cool. Nevermind.Thanks man. Edited April 27, 2010 by Sh3llC043r [size="5"] [/size] Link to comment Share on other sites More sharing options...
Spiff59 Posted April 27, 2010 Share Posted April 27, 2010 (edited) I'm not sure if this will be of any use to you... #include <Array.au3> ; for testing Global $aDriveInfo[20][6] _IMAPI2_Identify_Drives() ;------------------------------------------------------------------------------------------------------------------- Func _IMAPI2_Identify_Drives() $oDiscmaster = ObjCreate("IMAPI2.MsftDiscMaster2") If Not IsObj($oDiscmaster) Then Msgbox(1,"","Error accessing IMAPI2 (MsftDiscMaster2)") Exit EndIf $drives = 0 For $x = 0 To $oDiscmaster.Count() - 1 $oRecorder = ObjCreate("IMAPI2.MsftDiscRecorder2") If Not IsObj($oDiscmaster) Then Msgbox(1,"","objget error oRecorder") Exit EndIf If StringUpper(StringMid($oDiscmaster.Item($x), 5, 4)) <> "SCSI" Then ; bypass pseudo-SCSI drives which cause a crash $oRecorder.InitializeDiscRecorder($oDiscmaster.Item($x)) $drives += 1 $aDriveInfo[$drives][0] = $oDiscmaster.Item($x) ; Drive Identifier $z = $oRecorder.VolumePathNames $aDriveInfo[$drives][1] = $z[0] ; Drive Letter $aDriveInfo[$drives][2] = $oRecorder.VendorId $aDriveInfo[$drives][3] = $oRecorder.ProductId $aDriveInfo[$drives][4] = $oRecorder.ProductRevision $aDriveInfo[$drives][5] = $oRecorder.VolumeName EndIf Next $oDiscmaster = "" ReDim $aDriveInfo[$drives + 1][6] $aDriveInfo[0][0] = $drives _ArrayDisplay($aDriveInfo) ; for testing EndFunc Edit: (I don't have a flash drive around to see if they show up!) Edit2: I think that may only enumerate optical drives... Edited April 27, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now