JFX Posted November 19, 2009 Share Posted November 19, 2009 Hi! I'm, trying to get the this API PARTITION_INFORMATION_EX running in a dllcall.Thought I could use it the same way like in this topic Get disk number from drive letter but i guess it doesn't work soPlease can anyone help me with this?expandcollapse popupLocal $aCall = DllCall("kernel32.dll", "dword", "GetLogicalDrives") Local $iMask = $aCall[0] Local $tIOCTL_DISK_GET_PARTITION_INFO_EX = DllStructCreate("long_ptr StartingOffset;" & _ "long_ptr PartitionLength;" & _ "ulong PartitionNumber;") Local $hDevice Local $a_hCall, $a_iCall For $i = 0 To 25; alphabet (A = 0) If BitAND(BitShift($iMask, $i), 1) Then; drive exists $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & Chr(65 + $i) & ":", _; want handle to the logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) $hDevice = $a_hCall[0] $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x70048, _; IOCTL_DISK_GET_PARTITION_INFO_EX "ptr", 0, _ "dword", 0, _ "ulong_ptr", DllStructGetPtr($tIOCTL_DISK_GET_PARTITION_INFO_EX), _ "dword", DllStructGetSize($tIOCTL_DISK_GET_PARTITION_INFO_EX), _ "dword*", 0, _ "ptr", 0) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ConsoleWrite("Drive " & Chr(65 + $i) & ": " & @CRLF) ConsoleWrite(@TAB & "StartingOffset: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "StartingOffset") & @CRLF) ConsoleWrite(@TAB & "PartitionLength: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "PartitionLength") & @CRLF) ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "PartitionNumber") & @CRLF) ConsoleWrite(@CRLF) EndIf Next Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 19, 2009 Share Posted November 19, 2009 I ran it this way and suspiciously got the exact same handle for every drive. I don't think it's normal to get the same handle repeatedly like that. expandcollapse popupLocal $aCall = DllCall("kernel32.dll", "dword", "GetLogicalDrives") Local $iMask = $aCall[0] Local $tIOCTL_DISK_GET_PARTITION_INFO_EX = DllStructCreate("long_ptr StartingOffset;" & _ "long_ptr PartitionLength;" & _ "ulong PartitionNumber;") Local $hDevice Local $a_hCall, $a_iCall, $sDevice For $i = 0 To 25 ; alphabet (A = 0) If BitAND(BitShift($iMask, $i), 1) Then ; drive exists $sDevice = "\\.\" & Chr(65 + $i) & ":" ConsoleWrite($i & ": $sDevice = " & $sDevice & @LF) $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", $sDevice, _ ; want handle to the logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 128, _ ; FILE_ATTRIBUTE_NORMAL "ptr", 0) $hDevice = $a_hCall[0] ConsoleWrite($i & ": $hDevice = " & $hDevice & @LF) If $hDevice = -1 Then ContinueLoop ; Test for INVALID_HANDLE_VALUE $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x70048, _ ; IOCTL_DISK_GET_PARTITION_INFO_EX "ptr", 0, _ "dword", 0, _ "ulong_ptr", DllStructGetPtr($tIOCTL_DISK_GET_PARTITION_INFO_EX), _ "dword", DllStructGetSize($tIOCTL_DISK_GET_PARTITION_INFO_EX), _ "dword*", 0, _ "ptr", 0) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ConsoleWrite("Drive " & Chr(65 + $i) & ": " & @CRLF) ConsoleWrite(@TAB & "StartingOffset: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "StartingOffset") & @CRLF) ConsoleWrite(@TAB & "PartitionLength: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "PartitionLength") & @CRLF) ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_DISK_GET_PARTITION_INFO_EX, "PartitionNumber") & @CRLF) ConsoleWrite(@CRLF) EndIf Next By the way, you should be testing if $hDevice = -1, which is INVALID_HANDLE_VALUE, so you don't continue with an invalid handle. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Authenticity Posted November 20, 2009 Share Posted November 20, 2009 expandcollapse popupLocal Const $tagGUID1 = "uint Data1;ushort Data2;ushort Data3;ubyte Data4[8];" Local Const $tagPARTITION_INFORMATION_MBR = "ubyte PartitionType;ubyte BootIndicator;ubyte RecognizedPartition;uint HiddenSectors;" Local Const $tagPARTITION_INFORMATION_GPT = $tagGUID1 & $tagGUID1 & "uint64 Attributes;wchar Name[36];" Local Const $tagPARTITION_INFORMATION_EX_GPT = _ "int PartitionStyle;" & _ "int64 StartingOffset;" & _ "int64 PartitionLength;" & _ "uint PartitionNumber;" & _ "ubyte RewritePartition;" & _ $tagPARTITION_INFORMATION_GPT Local Const $tagPARTITION_INFORMATION_EX_MBR = _ "int PartitionStyle;" & _ "int64 StartingOffset;" & _ "int64 PartitionLength;" & _ "uint PartitionNumber;" & _ "ubyte RewritePartition;" & _ $tagPARTITION_INFORMATION_MBR & "dword[26];" Local $aCall = DllCall("kernel32.dll", "dword", "GetLogicalDrives") Local $iMask = $aCall[0] Local $tPIX = DllStructCreate($tagPARTITION_INFORMATION_EX_GPT) Local $hDevice Local $a_hCall, $a_iCall For $i = 0 To 25; alphabet (A = 0) If BitAND(BitShift($iMask, $i), 1) Then; drive exists $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & Chr(65 + $i) & ":", _; want handle to the logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) $hDevice = $a_hCall[0] $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x70048, _; IOCTL_DISK_GET_PARTITION_INFO_EX "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tPIX), _ "dword", DllStructGetSize($tPIX), _ "dword*", 0, _ "ptr", 0) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ConsoleWrite("Drive " & Chr(65 + $i) & ": " & @CRLF) ConsoleWrite(@TAB & "StartingOffset: " & DllStructGetData($tPIX, "StartingOffset") & @CRLF) ConsoleWrite(@TAB & "PartitionLength: " & DllStructGetData($tPIX, "PartitionLength") & @CRLF) ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tPIX, "PartitionNumber") & @CRLF) ConsoleWrite(@CRLF) EndIf Next Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 20, 2009 Share Posted November 20, 2009 Well, I was obviously wrong (again) about the handle repeating. Adding this to Authenticity's code shows the exact same handle for every drive, yet the handle obviously works: $hDevice = $a_hCall[0] ConsoleWrite($i & ": $hDevice = " & $hDevice & @LF) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JFX Posted November 20, 2009 Author Share Posted November 20, 2009 @PsaltyDS Thanks for pointing out INVALID_HANDLE_VALUE, guess I always forgot such a check. @Authenticity Works perfect,thanks a lot. Regards, JFX 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