# Loops

## Recommended Posts

Hi all,

I am very new to programming and have somewhat put this script together and would like to know what I am doing wrong. I have posted a different question before on a different path to solve the problem but I could not solve it due to complicated steps. I am trying to verify that a file exist on a USB drive to get the drive letter. After days of search I have found a script that does that and am trying to add it to the menu script that I had before. For some reason it will not run because the variables are not declared properly. I appreciate any help on this script. I'll be more than happy ro compensate financially (if allowed in the forum) for a working script.

Thanks

#include <GUIConstantsEx.au3>
#include <Process.au3>

Opt('MustDeclareVars', 1)

Local $Button_1,$Button_2, $Button_3,$font, $msg,$widthCell

GUICreate("Recovery Menu") ; will create a dialog box that when displayed is centered

$widthCell = 100 GUISetFont(11, 800, 4,$font)
GUICtrlCreateLabel("Restore and Recovery Utility", 1 * $widthCell, 15) GUISetFont(8.5, 400,$font)
GUICtrlCreateLabel("WARNING - This utility is intended for a quick recovery of the server.", 50, 50, 3 * $widthCell, 70) GUICtrlCreateLabel("PARTIAL RESTORE will restore the System Files ONLY!", 50, 120, 3 *$widthCell, 40)
GUICtrlCreateLabel("FULL RESTORE will restore the ENTIRE System!", 50, 160, 3 * $widthCell, 40) Opt("GUICoordMode", 2)$Button_1 = GUICtrlCreateButton("Partial Restore", -2 * $widthCell, 20, 100, 20)$Button_2 = GUICtrlCreateButton("Full Restore", -1, 30, 100, 20)
$Button_3 = GUICtrlCreateButton("Reboot", -1, 30, 100, 20) GUISetState() ; will display an dialog box with 3 button ; Run the GUI until the dialog is closed While 1$msg = GUIGetMsg()
Select
Case $msg =$GUI_EVENT_CLOSE
ExitLoop
If NOT @error Then
For $i = 1 to$var[0]
$drive =$var[$i] If FileExists($drive & "\recovery.wim") Then

MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)

RunWait(@ComSpec & " /c " & "\diskpart.exe /s", & $drive & "\partial-r.txt") ; Will Run/Open Partial Restore script RunWait(@ComSpec & " /c " & "\imagex.exe /apply ", &$drive & "\recovery.wim" & " 1 c:\")
EndIf
Next
EndIf
Case $msg =$Button_2
If NOT @error Then
For $i = 1 to$var[0]
$drive =$var[$i] If FileExists($drive & "\recovery.wim") Then

MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)
RunWait(@ComSpec & " /c " & "\diskpart.exe /s", & $drive & "\full-r.txt") ; Will Run/Open Partial Restore script RunWait(@ComSpec & " /c " & "\imagex.exe /apply ", &$drive & "\recovery.wim" & " 1 c:\")
EndIf
Next
EndIf
Case $msg =$Button_3
Exit
EndSelect
WEnd
EndFunc

##### Share on other sites

Yes you can have loops inside of each other. What exactly is the problem. Try rentacoder if you want someone to make it for you.

##### Share on other sites

Hi all,

I am very new to programming and have somewhat put this script together and would like to know what I am doing wrong. I have posted a different question before on a different path to solve the problem but I could not solve it due to complicated steps. I am trying to verify that a file exist on a USB drive to get the drive letter. After days of search I have found a script that does that and am trying to add it to the menu script that I had before. For some reason it will not run because the variables are not declared properly. I appreciate any help on this script. I'll be more than happy ro compensate financially (if allowed in the forum) for a working script.

Thanks

#include <GUIConstantsEx.au3>
#include <Process.au3>

Opt('MustDeclareVars', 1)

Local $Button_1,$Button_2, $Button_3,$font, $msg,$widthCell

GUICreate("Recovery Menu") ; will create a dialog box that when displayed is centered

$widthCell = 100 GUISetFont(11, 800, 4,$font)
GUICtrlCreateLabel("Restore and Recovery Utility", 1 * $widthCell, 15) GUISetFont(8.5, 400,$font)
GUICtrlCreateLabel("WARNING - This utility is intended for a quick recovery of the server.", 50, 50, 3 * $widthCell, 70) GUICtrlCreateLabel("PARTIAL RESTORE will restore the System Files ONLY!", 50, 120, 3 *$widthCell, 40)
GUICtrlCreateLabel("FULL RESTORE will restore the ENTIRE System!", 50, 160, 3 * $widthCell, 40) Opt("GUICoordMode", 2)$Button_1 = GUICtrlCreateButton("Partial Restore", -2 * $widthCell, 20, 100, 20)$Button_2 = GUICtrlCreateButton("Full Restore", -1, 30, 100, 20)
$Button_3 = GUICtrlCreateButton("Reboot", -1, 30, 100, 20) GUISetState() ; will display an dialog box with 3 button ; Run the GUI until the dialog is closed While 1$msg = GUIGetMsg()
Select
Case $msg =$GUI_EVENT_CLOSE
ExitLoop
If NOT @error Then
For $i = 1 to$var[0]
$drive =$var[$i] If FileExists($drive & "\recovery.wim") Then

MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)

RunWait(@ComSpec & " /c " & "\diskpart.exe /s", & $drive & "\partial-r.txt") ; Will Run/Open Partial Restore script RunWait(@ComSpec & " /c " & "\imagex.exe /apply ", &$drive & "\recovery.wim" & " 1 c:\")
EndIf
Next
EndIf
Case $msg =$Button_2
If NOT @error Then
For $i = 1 to$var[0]
$drive =$var[$i] If FileExists($drive & "\recovery.wim") Then

MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)
RunWait(@ComSpec & " /c " & "\diskpart.exe /s", & $drive & "\full-r.txt") ; Will Run/Open Partial Restore script RunWait(@ComSpec & " /c " & "\imagex.exe /apply ", &$drive & "\recovery.wim" & " 1 c:\")
EndIf
Next
EndIf
Case $msg =$Button_3
Exit
EndSelect
WEnd
EndFunc

I think you're missing at least this line, needed before your while loop starts

$var = DriveGetDrive( "all" ) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. #### Share this post ##### Link to post ##### Share on other sites Thanks for your response. I had considered rentacoder before. I had gone through a dozen screens and answered bunch of questions just to cancel out when I got to the payment information screen. I don't like to provide that much personal info before I have had a chance to converse with someone. This is a small project and I am hoping that I can find an interested individual to complete it for a fee. I think it will take less time getting what I have so far working than reapplying through them again. I do appreciate your response and suggestion. To answer your question about the problem, I think I am not declaring the$var = DriveGetDrive("removable") at the correct location. The error I get is "Variable used without being declared". The line of code is missing from the posted script, however I had included it in several locations (below 1st or 2nd Opt(), below GUISetState(), etc.) as trial.

Thanks

Yes you can have loops inside of each other. What exactly is the problem. Try rentacoder if you want someone to make it for you.

##### Share on other sites

Ok, I figured most everything out. I just have one last question regarding the RunWait command. I have created a second executable files running from within the fisrt menu.exe. This is the code for the second file. it loads fine and finds the correct USB drive but fails to run the RunWait codes. All the files are in two locations, System32 (except recovery.wim) and the root of the USB drive. Any idea what I have done wrong?

Thanks

$var = DriveGetDrive( "removable" ) If NOT @error Then For$i = 1 to $var[0]$drive = $var[$i]
If FileExists($drive & "\recovery.wim") Then RunWait(@ComSpec & " /c " & "diskpart.exe" & " /s" & "full-r.txt") RunWait(@ComSpec & " /c " & "imagex.exe" & " /apply" &$drive & "\recovery.wim" & " 1" & " c:\")

EndIf
Next
EndIf

##### Share on other sites

Ok, I figured most everything out. I just have one last question regarding the RunWait command. I have created a second executable files running from within the fisrt menu.exe. This is the code for the second file. it loads fine and finds the correct USB drive but fails to run the RunWait codes. All the files are in two locations, System32 (except recovery.wim) and the root of the USB drive. Any idea what I have done wrong?

Thanks

$var = DriveGetDrive( "removable" ) If NOT @error Then For$i = 1 to $var[0]$drive = $var[$i]
If FileExists($drive & "\recovery.wim") Then RunWait(@ComSpec & " /c " & "diskpart.exe" & " /s" & "full-r.txt") RunWait(@ComSpec & " /c " & "imagex.exe" & " /apply" &$drive & "\recovery.wim" & " 1" & " c:\")

EndIf
Next
EndIf

For debugging purposes, you can change "/c" to "/k" to keep the command prompts open, allowing you to see the errors.

(Change them back after you've fixed the syntax)

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

##### Share on other sites

For debugging purposes, you can change "/c" to "/k" to keep the command prompts open, allowing you to see the errors.

(Change them back after you've fixed the syntax)

I have done that. I have also split the imagex from diskpart codes. It tries to load diskpart but it can not find the script file. I figured I have the syntax wrong. I can run the commands manually and it runs it fine as> diskpart /s partial.txt. I would like to know if anyone has run diskpart under WinPE using a USB drive and compiled autoit script.

##### Share on other sites

I have done that. I have also split the imagex from diskpart codes. It tries to load diskpart but it can not find the script file. I figured I have the syntax wrong. I can run the commands manually and it runs it fine as> diskpart /s partial.txt. I would like to know if anyone has run diskpart under WinPE using a USB drive and compiled autoit script.

So, you confirmed that the syntax is wrong. Did you figure out why?

Change the " /k " to " /k echo " to see the exact command line being run.

I've compiled dozens of scripts that work fine in a PE environment. The trick is to understand the differences between that and a live system, and account for them.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

## Create an account

Register a new account

×

• Wiki

• Back

• Git