boy15 Posted November 12, 2018 Share Posted November 12, 2018 (edited) I had a complex issue in command prompt. diskpart list disk after that it will show all disks and storage devices connected into pc. suppose that I had 2 flash memory f - 8 GB G - 8 GB then it appear in command prompt disk 0 disk 1 disk 2 I want select flash memory (F) How I can know F flashmemory is disk 1 or disk 2 ( all flash memory have same size) ? Edited November 12, 2018 by boy15 Link to comment Share on other sites More sharing options...
Skeletor Posted November 12, 2018 Share Posted November 12, 2018 It goes by when you inserted the disk first.. F:\ is first therefore it is Disk 1... Disk 0 is your main operating disk... So its C:\ Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI Link to comment Share on other sites More sharing options...
caramen Posted November 12, 2018 Share Posted November 12, 2018 (edited) @boy15 Do you used my script ? Or you made one ? Past your code please... Edited November 12, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
boy15 Posted November 12, 2018 Author Share Posted November 12, 2018 22 minutes ago, caramen said: @boy15 Do you used my script ? Or you made one ? Past your code please... what is your script? Till Now I do not make script because I had problem to chooce disk Link to comment Share on other sites More sharing options...
caramen Posted November 12, 2018 Share Posted November 12, 2018 You can display a lot of info ising this way. Not only drive label. And you should use somthing else than diskpart. You got a WMI that can help you to manage things easyer than with diskpart, look : I give you this sample : ;Open a console then type: wmic logicaldisk get name ;Press Enter and you will see the list of Drives. ;You can also use the following parameter: wmic logicaldisk get caption ;List Drives in Command Prompt 2 ;Using the following will display Device ID and label: wmic logicaldisk get deviceid, volumename, description ;Fsutil tool fsutil fsinfo drives ;It will show mapped drives too. ;Diskpart tool diskpart ;Next use the following command: list volume This line should be the best for you : wmic logicaldisk get deviceid, volumename, description Try it : So you wont have to manage a dark HDD. You can have drive letter & description & label together to be sure of what you're are doing and where. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted November 12, 2018 Share Posted November 12, 2018 If you want to get the disk number you can use something like the following, similar to caramens but getting the actual disk number: Link to comment Share on other sites More sharing options...
caramen Posted November 12, 2018 Share Posted November 12, 2018 With WMI you can have evrything. expandcollapse popupuint16 Access; uint16 Availability; uint64 BlockSize; string Caption; boolean Compressed; uint32 ConfigManagerErrorCode; boolean ConfigManagerUserConfig; string CreationClassName; string Description; string DeviceID; uint32 DriveType; boolean ErrorCleared; string ErrorDescription; string ErrorMethodology; string FileSystem; uint64 FreeSpace; datetime InstallDate; uint32 LastErrorCode; uint32 MaximumComponentLength; uint32 MediaType; string Name; uint64 NumberOfBlocks; string PNPDeviceID; uint16 PowerManagementCapabilities[]; boolean PowerManagementSupported; string ProviderName; string Purpose; boolean QuotasDisabled; boolean QuotasIncomplete; boolean QuotasRebuilding; uint64 Size; string Status; uint16 StatusInfo; boolean SupportsDiskQuotas; boolean SupportsFileBasedCompression; string SystemCreationClassName; string SystemName; boolean VolumeDirty; string VolumeName; string VolumeSerialNumber; But btw... I want select flash memory (F) When i read this... maybe i am out of requested help... he maybe using diskpart forsomething else. But this can help anyway... let's see. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
boy15 Posted November 13, 2018 Author Share Posted November 13, 2018 It is for let flash memory as a bootable device I try write code but it is very difficult to join letter with disk number Link to comment Share on other sites More sharing options...
caramen Posted November 13, 2018 Share Posted November 13, 2018 5 hours ago, boy15 said: I try write code but it is very difficult to join letter with disk number What is the question ? What is difficult ? Post the full code ? My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Earthshine Posted November 13, 2018 Share Posted November 13, 2018 it's dos for crying out loud. how difficult could it be? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 13, 2018 Moderators Share Posted November 13, 2018 To the user who reported the post above, while I agree it adds nothing to the thread, I don't believe it is Quote needlessly grievous; uncalled for You need to grow a slightly thicker skin, especially since you are complaining about the member not being engaged in the thread yet you yourself have not been engaged in it either. Here's the little-known secret to happiness: if you see something you do not like, keep scrolling "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Earthshine Posted November 13, 2018 Share Posted November 13, 2018 (edited) Oh snap. Sorry. But I agree with others who have stated there are other ways to do this that are better even WMI Edited November 13, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
boy15 Posted November 14, 2018 Author Share Posted November 14, 2018 On 11/12/2018 at 4:34 PM, caramen said: I want select flash memory (F) When i read this... maybe i am out of requested help... he maybe using diskpart forsomething else. But this can help anyway... let's see. I want create bootable flash memory> https://docs.microsoft.com/en-us/windows-server-essentials/install/create-a-bootable-usb-flash-drive Can you help me Link to comment Share on other sites More sharing options...
ModemJunki Posted November 14, 2018 Share Posted November 14, 2018 Please have a look here first: There you can get all infos about the drives, including the MediaType (which for a flash drive should be "Removable Media" or similar) and the disk ID (the "Index"). Then maybe you can have a look here: Please post some example code of what you try, maybe then we can help more. Always carry a towel. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 14, 2018 Moderators Share Posted November 14, 2018 @boy15 you should realize by now from all of the responses you have received that this forum operates under the "Teach a Man to Fish" motto. We do not spoon-feed you code; you actually have to put some effort in. The whole "it's difficult just do it for me" doesn't work caramen and modemjunki have both given you solid suggestions to go on - try them for yourself, and then if you run into issues post your code and we will do our best to assist. boy15 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
boy15 Posted December 2, 2018 Author Share Posted December 2, 2018 expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $aArray = $sDDriveLetter $sDDriveLetter = DriveGetDrive($DT_REMOVABLE) $iDiskNumber = _GetDiskNimberForDrive($sDDriveLetter) If @error Then ; An error occurred when retrieving the drives. MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.") Else For $i = 1 To $aArray[0] _RunDos("diskpart") _RunDos("list disk") _RunDos("select disk " & $iDiskNumber) _RunDos("clean") _RunDos("create part pri") _RunDos("select part 1") _RunDos("format fs=ntfs quick") _RunDos("active") _RunDos("exit") Next EndIf Func _GetDiskNimberForDrive($sDriveLetter) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & $sDriveLetter & ":", _; logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) If @error Then Return SetError(1, 0, -1); your system is very old. Do something. EndIf If $a_hCall[0] = -1 Then Return SetError(2, 0, -1); non-existing drive EndIf Local $hDevice = $a_hCall[0] Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _ "dword DeviceNumber;" & _ "int PartitionNumber") Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword*", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) Return SetError(3, 0, -1); DeviceIoControl failed for some reason EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ; will write some data ConsoleWrite("Drive " & StringUpper($sDriveLetter) & ": " & @CRLF) ConsoleWrite(@TAB & "DeviceType: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") & @CRLF) ConsoleWrite(@TAB & "DeviceNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber") & @CRLF) ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber") & @CRLF) ConsoleWrite(@CRLF) ; end writing If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK Return SetError(0, 0, DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")) EndIf Return SetError(4, 0, -1); not a disk partition EndFunc ;==>_GetDiskNimberForDrive Link to comment Share on other sites More sharing options...
boy15 Posted December 3, 2018 Author Share Posted December 3, 2018 On 12/2/2018 at 8:23 AM, boy15 said: expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $aArray = $sDDriveLetter $sDDriveLetter = DriveGetDrive($DT_REMOVABLE) $iDiskNumber = _GetDiskNimberForDrive($sDDriveLetter) If @error Then ; An error occurred when retrieving the drives. MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.") Else For $i = 1 To $aArray[0] _RunDos("diskpart") _RunDos("list disk") _RunDos("select disk " & $iDiskNumber) _RunDos("clean") _RunDos("create part pri") _RunDos("select part 1") _RunDos("format fs=ntfs quick") _RunDos("active") _RunDos("exit") Next EndIf Func _GetDiskNimberForDrive($sDriveLetter) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & $sDriveLetter & ":", _; logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) If @error Then Return SetError(1, 0, -1); your system is very old. Do something. EndIf If $a_hCall[0] = -1 Then Return SetError(2, 0, -1); non-existing drive EndIf Local $hDevice = $a_hCall[0] Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _ "dword DeviceNumber;" & _ "int PartitionNumber") Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword*", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) Return SetError(3, 0, -1); DeviceIoControl failed for some reason EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ; will write some data ConsoleWrite("Drive " & StringUpper($sDriveLetter) & ": " & @CRLF) ConsoleWrite(@TAB & "DeviceType: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") & @CRLF) ConsoleWrite(@TAB & "DeviceNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber") & @CRLF) ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber") & @CRLF) ConsoleWrite(@CRLF) ; end writing If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK Return SetError(0, 0, DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")) EndIf Return SetError(4, 0, -1); not a disk partition EndFunc ;==>_GetDiskNimberForDrive Can any one correct this script Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 3, 2018 Moderators Share Posted December 3, 2018 @boy15 Please look at this post: You are not getting responses because you are not providing the information we need to assist. Rather than posting code snippets and expecting others to run the code, guess at what you're trying to do and then fix it for you, you need to provide detail as to what is not working, and what you have tried already to troubleshoot. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
ModemJunki Posted December 3, 2018 Share Posted December 3, 2018 Well, @JLogan3o13 I'll give the poster a little bit of fish but I won't fill their creel. I'm bored and need something productive to do for a few minutes. @boy15 the sample code posted is rubbish that doesn't even run past the first statement, were I your headmaster I would gleefully flog you in front of the other students for such terrible work. Please don't post untested code again, show your efforts and call out your failure points as you have been advised or you'll get no further help from me and most likely will continue to be ignored by the others who have popped in to give advice. For certain the part that you write to automate diskpart won't ever work. You have to write a text file with the diskpart commands then then script running diskpart (hint: look up the function RunWait). The commands that you wrote themselves might be OK, you'll have to validate them. I'm going to leave this diskpart stuff up to you - with a caution to be careful - it's no fun to erase the wrong disk. Now let us consider your erroneous use of the DriveGetDrive function, which returns an array that you must parse and extract the raw drive letter from and so is perhaps a bit advanced for you if you are new to AutoIT. Here I will show you how to get all the removable drive letters and indexes by re-working your code, you will see the output in the console. expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ;~ #include <array.au3> ; you need this if you want to use _arraydisplay() ConsoleWrite(@CRLF & "--------------------------------------------------------------" & @CRLF & @CRLF) $a_DDriveLetter = DriveGetDrive($DT_REMOVABLE) ;~ _arraydisplay($a_DDriveLetter) ; don't forget to include <array.au3> for this to work For $i = 1 To UBound($a_DDriveLetter) - 1 ConsoleWrite("Drive with letter " & $a_DDriveLetter[$i] & " has index of " & _GetDiskNimberForDrive(StringReplace($a_DDriveLetter[$i],":","")) & " in diskpart." & @CRLF) Next ConsoleWrite(@CRLF & "--------------------------------------------------------------" & @CRLF) ConsoleWrite(@CRLF & @CRLF) Func _GetDiskNimberForDrive($sDriveLetter) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & $sDriveLetter & ":", _; logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) If @error Then Return SetError(1, 0, -1); your system is very old. Do something. EndIf If $a_hCall[0] = -1 Then Return SetError(2, 0, -1); non-existing drive EndIf Local $hDevice = $a_hCall[0] Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _ "dword DeviceNumber;" & _ "int PartitionNumber") Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword*", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) Return SetError(3, 0, -1); DeviceIoControl failed for some reason EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ; will write some data ;~ ConsoleWrite("Drive " & StringUpper($sDriveLetter) & ": " & @CRLF) ;~ ConsoleWrite(@TAB & "DeviceType: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") & @CRLF) ;~ ConsoleWrite(@TAB & "DeviceNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber") & @CRLF) ;~ ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber") & @CRLF) ;~ ConsoleWrite(@CRLF) ; end writing If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK Return SetError(0, 0, DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")) EndIf Return SetError(4, 0, -1); not a disk partition EndFunc ;==>_GetDiskNimberForDrive Since the DriveGetDrive function returns the letters with a colon at the end we have to remove the colon somehow, StringReplace works for that by replacing the ":" with "". By no means am I an expert ... though perhaps I should study to become a headmaster. I could rather enjoy it, I think. Best of luck! Always carry a towel. Link to comment Share on other sites More sharing options...
boy15 Posted December 4, 2018 Author Share Posted December 4, 2018 Spoiler Spoiler 9 hours ago, ModemJunki said: Well, @JLogan3o13 I'll give the poster a little bit of fish but I won't fill their creel. I'm bored and need something productive to do for a few minutes. @boy15 the sample code posted is rubbish that doesn't even run past the first statement, were I your headmaster I would gleefully flog you in front of the other students for such terrible work. Please don't post untested code again, show your efforts and call out your failure points as you have been advised or you'll get no further help from me and most likely will continue to be ignored by the others who have popped in to give advice. For certain the part that you write to automate diskpart won't ever work. You have to write a text file with the diskpart commands then then script running diskpart (hint: look up the function RunWait). The commands that you wrote themselves might be OK, you'll have to validate them. I'm going to leave this diskpart stuff up to you - with a caution to be careful - it's no fun to erase the wrong disk. Now let us consider your erroneous use of the DriveGetDrive function, which returns an array that you must parse and extract the raw drive letter from and so is perhaps a bit advanced for you if you are new to AutoIT. Here I will show you how to get all the removable drive letters and indexes by re-working your code, you will see the output in the console. expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ;~ #include <array.au3> ; you need this if you want to use _arraydisplay() ConsoleWrite(@CRLF & "--------------------------------------------------------------" & @CRLF & @CRLF) $a_DDriveLetter = DriveGetDrive($DT_REMOVABLE) ;~ _arraydisplay($a_DDriveLetter) ; don't forget to include <array.au3> for this to work For $i = 1 To UBound($a_DDriveLetter) - 1 ConsoleWrite("Drive with letter " & $a_DDriveLetter[$i] & " has index of " & _GetDiskNimberForDrive(StringReplace($a_DDriveLetter[$i],":","")) & " in diskpart." & @CRLF) Next ConsoleWrite(@CRLF & "--------------------------------------------------------------" & @CRLF) ConsoleWrite(@CRLF & @CRLF) Func _GetDiskNimberForDrive($sDriveLetter) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _ "str", "\\.\" & $sDriveLetter & ":", _; logical drive "dword", 0, _ "dword", 0, _ "ptr", 0, _ "dword", 3, _; OPEN_EXISTING "dword", 128, _; FILE_ATTRIBUTE_NORMAL "ptr", 0) If @error Then Return SetError(1, 0, -1); your system is very old. Do something. EndIf If $a_hCall[0] = -1 Then Return SetError(2, 0, -1); non-existing drive EndIf Local $hDevice = $a_hCall[0] Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _ "dword DeviceNumber;" & _ "int PartitionNumber") Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDevice, _ "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _ "dword*", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) Return SetError(3, 0, -1); DeviceIoControl failed for some reason EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice) ; will write some data ;~ ConsoleWrite("Drive " & StringUpper($sDriveLetter) & ": " & @CRLF) ;~ ConsoleWrite(@TAB & "DeviceType: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") & @CRLF) ;~ ConsoleWrite(@TAB & "DeviceNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber") & @CRLF) ;~ ConsoleWrite(@TAB & "PartitionNumber: " & DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber") & @CRLF) ;~ ConsoleWrite(@CRLF) ; end writing If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK Return SetError(0, 0, DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")) EndIf Return SetError(4, 0, -1); not a disk partition EndFunc ;==>_GetDiskNimberForDrive Since the DriveGetDrive function returns the letters with a colon at the end we have to remove the colon somehow, StringReplace works for that by replacing the ":" with "". By no means am I an expert ... though perhaps I should study to become a headmaster. I could rather enjoy it, I think. Best of luck! I hit autoiscript 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