Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 20:15

  • Please register to post and access all features, it's quick, easy and FREE!


call for help

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2008
Posts: 5
Received Thanks: 0
call for help

Hi,
I can let usb storage as a bootable device via command prompt>

I want execute that commands during scripts but I had problem about disk number for usb storage.

https://docs.microsoft.com/en-us/win...sb-flash-drive

I want make tool when I choose flash automatically execute all commands and convert as a bootable device.



boy25 is offline  
Old 12/04/2018, 05:10   #2
 
elite*gold: 0
Join Date: Nov 2008
Posts: 5
Received Thanks: 0
Code:
#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
can any one help me


boy25 is offline  
Old 12/08/2018, 16:48   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 247
Received Thanks: 83
Code:
#RequireAdmin
#include <AutoItConstants.au3>
#include <WinAPI.au3>

$a_DDriveLetter = DriveGetDrive($DT_REMOVABLE)
For $i = 1 To UBound($a_DDriveLetter) - 1
   $letter = StringReplace(StringUpper($a_DDriveLetter[$i]),":","")
$handle =   FileOpen("script-drive-"&$letter&".txt",2)
	FileWrite($handle,"select volume " &$letter & @CRLF & _
											 "clean" & @CRLF & _
											 "create part pri"  & @CRLF & _
											 "select part 1"  & @CRLF & _
											 "format fs=ntfs quick"  & @CRLF & _
											 "active"  & @CRLF & _
											 "exit" & @CRLF)
 FileClose($handle)
ShellExecute("script-drive-"&$letter&".txt")
WinWaitActive("[CLASS:Notepad]")
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to execute the resulting script",0,_WinAPI_GetForegroundWindow())
if $confirm = 6 Then Run(@ComSpec & " /C diskpart /s script-drive-"&$letter&".txt",@ScriptDir,@SW_SHOW,0x10000);Execute diskpart script

Next
elmarcia is offline  
Old 12/11/2018, 05:10   #4
 
elite*gold: 0
Join Date: Nov 2008
Posts: 5
Received Thanks: 0
thanks my sir
Can I let Notepad as hidden. Not show for user who use this script.


boy25 is offline  
Old 12/11/2018, 16:10   #5
 
elite*gold: 0
Join Date: Apr 2011
Posts: 247
Received Thanks: 83
Quote:
Originally Posted by boy25 View Post
thanks my sir
Can I let Notepad as hidden. Not show for user who use this script.
sure, remove those lines
Code:
ShellExecute("script-drive-"&$letter&".txt")
WinWaitActive("[CLASS:Notepad]")
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to execute the resulting script",0,_WinAPI_GetForegroundWindow())
if $confirm = 6 Then Run(@ComSpec & " /C diskpart /s script-drive-"&$letter&".txt",@ScriptDir,@SW_SHOW,0x10000);Execute diskpart script
and leave
Code:
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to make bootable device at letter 
 "&$letter,0,_WinAPI_GetForegroundWindow())
if $confirm = 6 Then 
$pid = Run(@ComSpec & " /C diskpart /s script-drive-"&$letter&".txt",@ScriptDir,@SW_SHOW,0x10000);Execute diskpart script
ProcessWaitClose($pid)
FileClose($handle)
FileDelete("script-drive-"&$letter&".txt);remove script file
endif
elmarcia is offline  
Old 12/12/2018, 06:24   #6
 
elite*gold: 0
Join Date: Nov 2008
Posts: 5
Received Thanks: 0
Code:
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to make bootable device at letter"
 & $letter,0,_WinAPI_GetForegroundWindow())
what is wrong in this?
boy25 is offline  
Old 12/12/2018, 15:48   #7
 
elite*gold: 0
Join Date: Apr 2011
Posts: 247
Received Thanks: 83
Quote:
Originally Posted by boy25 View Post
Code:
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to make bootable device at letter"
 & $letter,0,_WinAPI_GetForegroundWindow())
what is wrong in this?
remove the break line
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to make bootable device at letter"&$letter,0,_WinAPI_GetForegroundWindow())
elmarcia is offline  
Old 12/12/2018, 20:57   #8
 
elite*gold: 0
Join Date: Nov 2008
Posts: 5
Received Thanks: 0
Quote:
Originally Posted by elmarcia View Post
remove the break line
$confirm = MsgBox(0x4,"Confirm","Are u sure u want to make bootable device at letter"&$letter,0,_WinAPI_GetForegroundWindow())
It is very important. Maybe there is method to keep message


boy25 is offline  
Reply



« Hilfe! | - »



All times are GMT +1. The time now is 20:15.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.