Jump to content
Sign in to follow this  
boy15

complex issue in dos

Recommended Posts

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 by boy15

Share this post


Link to post
Share on other sites

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 Regards
Skeletor

"I need coffee to turn me back to a human"

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen

Share this post


Link to post
Share on other sites

@boy15 Do you used my script ?

Or you made one ? Past your code please...

Edited by caramen

My video tutorials : HERE ( 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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 : 

image.png.26216b3f09b198c82f26df7de65daf9e.png

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 : HERE ( 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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

If you want to get the disk number you can use something like the following, similar to caramens but getting the actual disk number:

 

Share this post


Link to post
Share on other sites

With WMI you can have evrything. 

uint16   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 : HERE ( 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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 : HERE ( 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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Oh snap. Sorry. But I agree with others who have stated there are other ways to do this that are better even WMI

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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.


"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!

Share this post


Link to post
Share on other sites
  • #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

     

Share this post


Link to post
Share on other sites
On ‎12‎/‎2‎/‎2018 at 8:23 AM, boy15 said:
  • #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

Share this post


Link to post
Share on other sites

@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!

Share this post


Link to post
Share on other sites

Well, @JLogan3o13 I'll give the poster a little bit of fish but I won't fill their creel. o:) 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. :blink:

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.

#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. :D

Best of luck!


Always carry a towel.

Share this post


Link to post
Share on other sites
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. o:) 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. :blink:

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.

#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. :D

Best of luck!

 

 

I hit autoiscript

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...