Elephant007 Posted November 19, 2010 Share Posted November 19, 2010 Building a simple script to help my fellow technicians image computers with Windows 7. I have everything figured out with a DOS script utilizing GImageX. I would like to Autoit this instead. Basically I run this code below which gets me the first part lstdsk = list disk RunWait ("cmd /c diskpart /s dsk\lstdsk > dsk\lstdsk.txt", "", @SW_HIDE ) $file = FileOpen("dsk\lstdsk.txt", 0) That gets me a text file that I then read with this part of the script And puts it in s a GUICtrlCreateList (code not complete) Func Example() Local $menu1, $n1, $n2, $msg, $menustate, $menutext, $file, $file = FileOpen("dsk\lstdsk.txt", 0) $Line8 = FileReadLine ($file, 8) $Line9 = FileReadLine ($file, 9) GUICreate("Select Disk To Format", 260, 250) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel ( "Avaliable Disks", 22, 10, 100) $n1 = GUICtrlCreateList("", 20, 30, 215, 150) GUICtrlSetData( -1, $Line8 & "|" & $Line9) ;, $Line8 ) $n2 = GUICtrlCreateButton("Select This Disk to Format", 28, 200, 200) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $msg = GUIGetMsg() If $msg = $n2 Then MsgBox(0, "Selected listbox entry", GUICtrlRead($n1)) ; display the selected listbox entry EndIf Until $msg = $GUI_EVENT_CLOSE EndFunc The problem I'm running into is the output message contains the whole line of the text file that was read in FileReadLine. I need to know if there is a way to either get the first number that appears on the line or assign a value to $Line#... e.g $Line8 = 0 Link to comment Share on other sites More sharing options...
Varian Posted November 20, 2010 Share Posted November 20, 2010 (edited) Does this help?#include <GUIConstantsEx.au3> #include <String.au3> RunWait("cmd /c diskpart /s lstdsk.ini > lstdsk.txt", "", @SW_HIDE) Example() Func Example() Local $Menu1, $n1, $n2, $Msg, $menustate, $menutext, $File Local $Line, $Array = _StringExplode(FileRead('lstdsk.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|]* , '') ;trim spaces, returns, line breaks, and pipes from end of the string GUICreate("Select Disk To Format", 260, 250) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel("Avaliable Disks", 22, 10, 100) $n1 = GUICtrlCreateList("", 20, 30, 215, 150) GUICtrlSetData(-1, $Line) $n2 = GUICtrlCreateButton("Select This Disk to Format", 28, 200, 200) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $Msg = GUIGetMsg() If $Msg = $n2 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).* , '$1') MsgBox(0, "Selected listbox entry", $Disk) ; display the selected listbox entry EndIf Until $Msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Edited November 20, 2010 by Varian Link to comment Share on other sites More sharing options...
JoHanatCent Posted November 20, 2010 Share Posted November 20, 2010 MsgBox(0, "Selected listbox entry", StringLeft(StringRegExpReplace(GUICtrlRead($n1), '[a-zA-Z]|\W', ''),1)) Link to comment Share on other sites More sharing options...
Elephant007 Posted November 20, 2010 Author Share Posted November 20, 2010 Thank you both for your replies Varian: I am getting this error when I run the script your provided " ==> Unterminated string.: $Line = StringRegExpReplace($Line, '[\s|]* , '') ;trim spaces, returns, line breaks, and pipes from end of the string " JoHanatCent: When I added your line, I always get 0 as the output in the msgbox This is in the right direction, thank you both again Link to comment Share on other sites More sharing options...
Varian Posted November 20, 2010 Share Posted November 20, 2010 (edited) For some reason certain parts of the code that I paste are being truncated. The line in question should read:$Line = StringRegExpReplace($Line, '[\s|]* , '') ;trim spaces, returns, line breaks, and pipes from end of the string I also failed to create the lstdsk.ini file which has the commands for diskpart. That is done in the first 3 lines after the #includes. Here is the entire script again just in case..I've checked to make sure that when I copy what I have posted, there are no errors in the script#include <GUIConstantsEx.au3> #include <String.au3> $File = FileOpen('lstdsk.ini', 2) FileWrite($File, 'list disk') FileClose($File) RunWait("cmd /c diskpart /s lstdsk.ini > lstdsk.txt", "", @SW_HIDE) Example() Func Example() Local $Menu1, $n1, $n2, $Msg, $menustate, $menutext, $File Local $Line, $Array = _StringExplode(FileRead('lstdsk.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|]*$' , '') ;trim spaces, returns, line breaks, and pipes from end of the string GUICreate("Select Disk To Format", 260, 250) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel("Avaliable Disks", 22, 10, 100) $n1 = GUICtrlCreateList("", 20, 30, 215, 150) GUICtrlSetData(-1, $Line) $n2 = GUICtrlCreateButton("Select This Disk to Format", 28, 200, 200) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $Msg = GUIGetMsg() If $Msg = $n2 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$' , '$1') MsgBox(0, "Selected listbox entry", $Disk) ; display the selected listbox entry EndIf Until $Msg = $GUI_EVENT_CLOSE EndFunc ;==>Example EDIT: My problem was enabling the Rich Text Editor in my profile..disabled that and all is well now,. Edited November 20, 2010 by Varian donhorn20 1 Link to comment Share on other sites More sharing options...
Varian Posted November 20, 2010 Share Posted November 20, 2010 Hey Elephant007, have you found a way to automate bootrec.exe? I have made Syspreped Win 7 Pro images that I load via PE or MDT. I don't like MDT as much and I have created a PE image with most tools that I need, including bootrec.exe from the Recovery image. the only part that I cannot totally automate is running bootrec.exe after I load the image onto the machine. Let me know if you find any help with this Link to comment Share on other sites More sharing options...
Elephant007 Posted November 21, 2010 Author Share Posted November 21, 2010 Hey Elephant007, have you found a way to automate bootrec.exe? I have made Syspreped Win 7 Pro images that I load via PE or MDT. I don't like MDT as much and I have created a PE image with most tools that I need, including bootrec.exe from the Recovery image. the only part that I cannot totally automate is running bootrec.exe after I load the image onto the machine. Let me know if you find any help with thisYour script worked great! Now if I could modify it so the MsgBox is Yes/No, clicking YES then it writes a line into an exiting file.I know how to open a file and write into the file and close the file, I'm just not sure how to tweak the script to click yes to complete thisAs far as fixing the boot, this is what I didMount boot.wim from sources directory on the Win7 DVDcopy the following files from your Windows 7 DVD to your winpe source (I use USB)\windows\system32\Bootrec.exe\windows\system32\wer.dll\windows\system32\en-US\Bootrec.exe.mui\windows\system32\en-US\wer.dll.muafter imaging your computer, run STARTREP.EXE and this will make the target drive bootableHope this is what you were asking about Link to comment Share on other sites More sharing options...
Varian Posted November 21, 2010 Share Posted November 21, 2010 Here is a MsgBox Wizard that will help you create the custom MsgBox to suit your needs...This is not my code. The source can be found I had to add some includes for the updated version of AutoIT.expandcollapse popup;=============================================================================== ; ; Program Name: MsgBoxWizard() ; Description: Generate the MessageBox function code according to the user ; choices ; Requirement(s): None ; Return Value(s): None ; Author(s): Giuseppe Criaco <gcriaco@quipo.it> ; Revision(s) by: Aaron Robinson <aaronr@bgnet.bgsu.edu> ; Last Revision: May 24, 2005 ; ; Revision Summary: ; -Added a code box to display real-time the code being generated ; -Made the code generating syntax a seperate function making it easier ; to use multiple times. ; -Adjusted the GUI to account for the new text box (Assumed 800x600 screen size) ; -Added a test for resolutions and slightly adjusted starting position ; ;=============================================================================== ; #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Global $iFlag, $Button, $counter, $tempMsgbox Const $init = 10 If @DesktopHeight <= 600 Then MsgBox(48,"Caution!","This program is best viewed in screen resolutions greater than 800x600.") GUICreate("MsgBox Wizard v.1.1", 440, 570, 50, 0) ; will create a dialog box for 800x600 or less Else GUICreate("MsgBox Wizard v.1.1", 440, 570, 100, 100) ; will create a dialog box for all others EndIf GUICtrlCreateLabel("Title", 10, 5, 30) $TITLE = GUICtrlCreateInput("", 10, 20, 420, 20) GUICtrlSetState ( -1, $GUI_FOCUS) GUICtrlSetTip(-1, "The title of the message box.") GUICtrlCreateLabel("Text", 10, 50, 30) $TEXT = GUICtrlCreateEdit("", 10, 65, 420, 50, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_WANTRETURN) GUICtrlSetTip(-1, "The text of the message box.") GUICtrlCreateGroup("Icons", 10, 120, 200, 130) $optWarning = GUICtrlCreateRadio("Warning", 20, 140, 100, 20) GUICtrlSetState(-1, $GUI_CHECKED) $optInfo = GUICtrlCreateRadio("Informational", 20, 160, 100, 20) $optCritical = GUICtrlCreateRadio("Critical", 20, 180, 100, 20) $optQuestion = GUICtrlCreateRadio("Question", 20, 200, 100, 20) $optNoIcon = GUICtrlCreateRadio("None", 20, 220, 100, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateGroup("Modality", 10, 260, 200, 90) $optApplication = GUICtrlCreateRadio("Application", 20, 280, 100, 20) GUICtrlSetState(-1, $GUI_CHECKED) $optSysModal = GUICtrlCreateRadio("System Modal", 20, 300, 100, 20) $optTaskModal = GUICtrlCreateRadio("Task Modal", 20, 320, 100, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateGroup("Buttons", 230, 120, 200, 170) $optOK = GUICtrlCreateRadio("OK", 240, 140, 100, 20) GUICtrlSetState(-1, $GUI_CHECKED) $optOkCancel = GUICtrlCreateRadio("OK, Cancel", 240, 160, 100, 20) $optYesNo = GUICtrlCreateRadio("Yes, No", 240, 180, 100, 20) $optYesNoCancel = GUICtrlCreateRadio("Yes, No, Cancel", 240, 200, 100, 20) $optAbortRetryIgnore = GUICtrlCreateRadio("Abort, Retry, Ignore", 240, 220, 120, 20) $optRetryCancel = GUICtrlCreateRadio("Retry, Cancel", 240, 240, 100, 20) $optCancelRetryContinue = GUICtrlCreateRadio("Cancel, Retry, Continue", 240, 260, 130, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateGroup("Miscellaneous", 10, 360, 200, 90) $optNothing = GUICtrlCreateRadio("Nothing", 20, 380, 100, 20) GUICtrlSetState(-1, $GUI_CHECKED) $optTopMost = GUICtrlCreateRadio("Top-most attribute set", 20, 400, 130, 20) $optRightJust = GUICtrlCreateRadio("Right-justified title/text", 20, 420, 150, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateGroup("Default Buttons", 230, 300, 200, 90) $optFirst = GUICtrlCreateRadio("First Button", 240, 320, 130, 20) GUICtrlSetState(-1, $GUI_CHECKED) $optSecond = GUICtrlCreateRadio("Second Button", 240, 340, 130, 20) GUICtrlSetState(-1, $GUI_DISABLE) $optThird = GUICtrlCreateRadio("Third Button", 240, 360, 130, 20) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateGroup("Timeout", 230, 400, 200, 50) $Timeout = GUICtrlCreateInput("", 240, 420, 100, 20, $ES_NUMBER) GUICtrlSetTip(-1, "Optional Timeout in seconds. After the timeout has elapsed the message box will be automatically closed.") GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUICtrlCreateLabel("Code", 10, 455, 30) $CODE = GUICtrlCreateEdit("", 10, 470, 420, 60, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_WANTRETURN) GUICtrlSetTip(-1, "What the code looks like.") GUICtrlSetData(-1, "Press the Copy Button to get the Code.") $BTNPREVIEW = GUICtrlCreateButton("&Preview", 10, 535, 100) GUICtrlSetTip(-1, "Show the MessageBox") $BTNCOPY = GUICtrlCreateButton("&Copy", 120, 535, 100) GUICtrlSetTip(-1, "Copy the generated AutoIt code to the Clipboard") $BTNEXIT = GUICtrlCreateButton("E&xit", 230, 535, 100) GUICtrlSetTip(-1, "Quit the program") $Button = $optOK $counter = $init GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed While 1 $MSG = GUIGetMsg() If $tempMsgbox <> _SetMsgText() Then $tempMsgbox = _SetMsgText() GUICtrlSetData($CODE, $tempMsgbox ) EndIf Select Case $MSG = $GUI_EVENT_CLOSE Or $MSG = $BTNEXIT Exit Case $MSG = $optOK $Button = $optOK GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_DISABLE) GUICtrlSetState($optThird, $GUI_DISABLE) Case $MSG = $optOkCancel $Button = $optOkCancel GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_DISABLE) Case $MSG = $optYesNo $Button = $optYesNo GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_DISABLE) Case $MSG = $optYesNoCancel $Button = $optYesNoCancel GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_ENABLE) Case $MSG = $optAbortRetryIgnore $Button = $optAbortRetryIgnore GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_ENABLE) Case $MSG = $optRetryCancel $Button = $optRetryCancel GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_DISABLE) Case $MSG = $optCancelRetryContinue $Button = $optCancelRetryContinue GUICtrlSetState($optFirst, $GUI_CHECKED) GUICtrlSetState($optFirst, $GUI_ENABLE) GUICtrlSetState($optSecond, $GUI_ENABLE) GUICtrlSetState($optThird, $GUI_ENABLE) Case $MSG = $BTNPREVIEW MsgBox(_SetFlag($iFlag), GUICtrlRead($TITLE), GUICtrlRead($TEXT), GUICtrlRead($Timeout)) Case $MSG = $BTNCOPY ClipPut( _SetMsgText() ) EndSelect Wend ;=============================================================================== ; ; Function Name: _SetFlag() ; Description: Set the flag that indicates the type of message box and the ; possible button combinations. ; Parameter(s): $iFlag - Flag ; Requirement(s): None ; Return Value(s): On Success - Returns the message box flag ; None ; Author(s): Giuseppe Criaco <gcriaco@quipo.it> ; ;=============================================================================== ; Func _SetFlag($iFlag) $iFlag = 0 ;Icons Select Case GUICtrlRead($optWarning) = $GUI_CHECKED $iFlag = $iFlag + 48 Case GUICtrlRead($optInfo) = $GUI_CHECKED $iFlag = $iFlag + 64 Case GUICtrlRead($optCritical) = $GUI_CHECKED $iFlag = $iFlag + 16 Case GUICtrlRead($optQuestion) = $GUI_CHECKED $iFlag = $iFlag + 32 EndSelect ;Modality Select Case GUICtrlRead($optSysModal) = $GUI_CHECKED $iFlag = $iFlag + 4096 Case GUICtrlRead($optTaskModal) = $GUI_CHECKED $iFlag = $iFlag + 8192 EndSelect ;Buttons Select Case GUICtrlRead($optOkCancel) = $GUI_CHECKED $iFlag = $iFlag + 1 Case GUICtrlRead($optYesNo) = $GUI_CHECKED $iFlag = $iFlag + 4 Case GUICtrlRead($optYesNoCancel) = $GUI_CHECKED $iFlag = $iFlag + 3 Case GUICtrlRead($optAbortRetryIgnore) = $GUI_CHECKED $iFlag = $iFlag + 2 Case GUICtrlRead($optRetryCancel) = $GUI_CHECKED $iFlag = $iFlag + 5 Case GUICtrlRead($optCancelRetryContinue) = $GUI_CHECKED $iFlag = $iFlag + 6 EndSelect ;Miscellaneous Select Case GUICtrlRead($optTopMost) = $GUI_CHECKED $iFlag = $iFlag + 262144 Case GUICtrlRead($optRightJust) = $GUI_CHECKED $iFlag = $iFlag + 5244288 EndSelect ;Default Buttons Select Case GUICtrlRead($optSecond) = $GUI_CHECKED $iFlag = $iFlag + 256 Case GUICtrlRead($optThird) = $GUI_CHECKED $iFlag = $iFlag + 512 EndSelect Return $iFlag EndFunc ;==>_SetFlag ;=============================================================================== ; ; Function Name: _SetMsgText() ; Description: Set the code for the message box. Used from the copy and ; the code box ; Parameter(s): $asMsgText - string for the user entered text ; $msgbox - string for the code being returned ; Requirement(s): None ; Return Value(s): On Success - Returns a string containing the code ; None ; Author(s): Giuseppe Criaco <gcriaco@quipo.it> ; Editor(s): Aaron Robinson <aaronr@bgnet.bgsu.edu> ; ;=============================================================================== ; Func _SetMsgText() Local $asMsgText, $msgbox $asMsgText = StringSplit(GUICtrlRead($TEXT), @CRLF, 1) If $asMsgText[0] = 1 Then $sText = GUICtrlRead($TEXT) Else $sText = $asMsgText[1] For $iCtr = 2 To $asMsgText[0] $sText = $sText & Chr(34) & " & @CRLF & " & Chr(34) & $asMsgText[$iCtr] Next EndIf Select Case $Button = $optOK If GUICtrlRead($Timeout) = "" Then $msgbox = "MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ " Case Else ;OK" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optOkCancel If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 1 ;OK" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 1 ;OK" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optYesNo If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 6 ;Yes" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 7 ;No" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 6 ;Yes" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 7 ;No" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optYesNoCancel If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 6 ;Yes" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 7 ;No" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 6 ;Yes" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 7 ;No" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optAbortRetryIgnore If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 3 ;Abort" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 4 ;Retry" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 5 ;Ignore" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 3 ;Abort" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 4 ;Retry" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 5 ;Ignore" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optRetryCancel If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 4 ;Retry" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 4 ;Retry" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf Case $Button = $optCancelRetryContinue If GUICtrlRead($Timeout) = "" Then $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 10 ;Try Again" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 11 ;Continue" & @CRLF & @CRLF & _ "EndSelect" Else $msgbox = "Dim $iMsgBoxAnswer" & @CRLF & _ "$iMsgBoxAnswer = MsgBox(" & _SetFlag($iFlag) & "," & Chr(34) & GUICtrlRead($TITLE) & Chr(34) & "," _ & Chr(34) & $sText & Chr(34) & "," & GUICtrlRead($Timeout) & ")" & @CRLF & _ "Select" & @CRLF & _ " Case $iMsgBoxAnswer = 2 ;Cancel" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 10 ;Try Again" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = 11 ;Continue" & @CRLF & @CRLF & _ " Case $iMsgBoxAnswer = -1 ;Timeout" & @CRLF & @CRLF & _ "EndSelect" EndIf EndSelect Return $msgbox EndFunc Link to comment Share on other sites More sharing options...
Varian Posted November 21, 2010 Share Posted November 21, 2010 Here is an example with your msgboxexpandcollapse popup#include <GUIConstantsEx.au3> #include <String.au3> $File = FileOpen(@TempDir & '\lstdsk.ini', 2) FileWrite($File, 'list disk') FileClose($File) RunWait('cmd /c diskpart /s lstdsk.ini > lstdsk.txt', @TempDir, @SW_HIDE) Example() Func Example() Local $Menu1, $n1, $n2, $Msg, $Menustate, $Menutext, $File Local $Line, $Array = _StringExplode(FileRead(@TempDir & '\lstdsk.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|]*$', '') ;trim spaces, returns, line breaks, and pipes from end of the string GUICreate('Select Disk To Format', 260, 250) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel('Avaliable Disks', 22, 10, 100) $n1 = GUICtrlCreateList('', 20, 30, 215, 150) GUICtrlSetData(-1, $Line) $n2 = GUICtrlCreateButton('Select This Disk to Format', 28, 200, 200) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUISetState() ; will display an empty dialog box ; Run the GUI until the dialog is closed Do $Msg = GUIGetMsg() If $Msg = $n2 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1') Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(262452, 'Selected Drive To Format is: ' & $Disk, 'Proceed with Format of ' & $Disk & '?') Select Case $iMsgBoxAnswer = 6 ;Yes _Format($Disk) Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf Until $Msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _Format($Drive) GUISetState(@SW_HIDE) Local $String, $Text = 'This is the script that you can send to diskpart' & @LF & 'The file is located at: ' & @TempDir & '\format.txt' $String &= 'Select ' & $Drive & @CRLF $String &= 'Clean' & @CRLF $String &= 'Create Partition Primary' & @CRLF $String &= 'Select Partition 1' & @CRLF $String &= 'Format fs=NTFS Quick' & @CRLF $String &= 'Active' & @CRLF $String &= 'Exit' $File = FileOpen(@TempDir & '\format.txt', 2) FileWrite($File, $String) FileClose($File) ShellExecute(@TempDir & '\format.txt', '', '', 'open') MsgBox(262144, 'Diskpart Script Created for ' & $Drive, $Text) GUISetState() EndFunc ;==>_Format 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