Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/21/2022 in all areas

  1. Dan_555

    Help for my project

    The Func Install_soft() is missing an Endfunc The otherproblem can be that you are using absolute paths ... see: ""C:\Users\ssuk10g\Desktop\autoIT\teste\Envio_softwares_VWStore\" The other machine should have the same user for this to work ... you can use @desktopdir to access the current user desktop folder 3rd problem ... you are deleting the gui and then there is a loop where you check the buttons ... You should hide the gui instead of deleting it.
    1 point
  2. Check log of your AV. Whitelist the AutoIt folder and your script folder (you may have to add some other folders).
    1 point
  3. I am making a basic GUI for Diskpart using examples I have found across your forum, for the purpose of preparing a hard drive for WinNTSetup5. It will format the selected drive in your choice of either MBR or GPT layout then edit WinNTSetup.ini and add the appropriate drive letters to simplify using WinNTSetup5 to install windows. With this GUI you simply select your layout and when WinNTSetup5 opens you just pick your ISO, edition, then click setup.. Otherwise you would have to manually format everything correctly etc, it is tedious to say the least. You place it in a subfolder with a name of your choosing of WinNTSetup5 (e.g. WinNTSetup5\Prep) and it will traverse up one level to edit\create the INI settings with the correct drive letters. (This file is to be created by the user with intended settings, per the authors instruction.) After testing hundreds of formats on diff style drives, internal and external I found breaking up the diskpart commands, even though recommended against by microsoft, it works every time and not as a single diskpart script.. (idk why this is true?) With that long winded explanation out of the way, the below code works perfectly fine. But I am wondering if there is an easy way to move the GUI out of the _SelectDrive function so I can be a little more versatile with this. I'm not sure if there is even a problem with it but it feels like a large part of the program is nested in a function and it shouldnt be? I am a beginner, I know its ugly, advice or examples very much appreciated ***This WILL format the selected drive if you tell it to. Use caution if you test it. #NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> $listiniFile = (@WorkingDir & '\cache\list.ini') $listtxtFile = (@WorkingDir & '\cache\list.txt') $File = "" $bootDrive = "" $mainDrive = "" $driveletter = StringSplit("C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z",",",1) _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'list disk') FileClose($listFile) RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 _SelectDrive() Func _SelectDrive() Local $Menu1, $n1, $n2, $n3, $Msg, $Menustate, $Menutext Local $Line, $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $i = 0 To UBound($Array) - 1 If StringRegExp($Array[$i], '(?i)Disk [\d]+') Then $Line &= $Array[$i] & '|' Next $Line = StringRegExpReplace($Line, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string GUICreate('Prep/Format Disk v1.1', 300, 277) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $n1 = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Line) GUICtrlCreateLabel('2: Select your desired layout...', 20, 187, 280, 30) $n2 = GUICtrlCreateButton('BIOS (MBR) Boot',20, 205, 120, 40) $n3 = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 205, 120, 40) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 251, 130, 30) GUISetState() _GetDriveLetters() Do $Msg = GUIGetMsg() If $Msg = $n2 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Msg = $n3 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf Until $Msg = $GUI_EVENT_CLOSE _Cleanup() EndFunc ;==>_SelectDrive (MAIN) Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileWrite($scrubdatFile, @CRLF & 'clean') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Setting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, @CRLF & 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(20 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() For $i = 1 to $driveletter[0] step +1 $var = DriveStatus( $driveletter[$i] & ":" ) If $var = "INVALID" Then $bootDrive=($driveletter[$i]) For $i = 1 to $driveletter[0] step +1 $var = DriveStatus( $driveletter[$i] & ":" ) If $var = "INVALID" Then $mainDrive=($driveletter[$i]) EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters
    1 point
×
×
  • Create New...