grunewald6 Posted October 19, 2008 Share Posted October 19, 2008 Ok, I'm pretty new at this but I've been teaching myself AutoIT by using the help file and reading this forum. I'm making a user profile backup/restore tool to use at work to ease reimaging of our computers. I want my script to check for the user's profile to make sure it was not mistyped before it runs the backup. I can't get it to work quite right. I've made this function to check for the user: Func CheckUser () $username = guictrlread($input) If not FileExists("C:\documents and settings\" & $username) Then MsgBox(0, "Error", "Check spelling. That user profile is not on this computer.") EndIf EndFuncThis is the main program run: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Backup Checkuser () Backup () ;Will Run Backup Function Exit Case $msg = $Restore Restore () ;Will Run Restore Function exit EndSelect WEndWhat I need is for it to start over or wait for the username to be changed in the input box after it sees that the username is not valid. Can anyone help? Sorry if this isn't enough info to explain my prob. Any help is appreciated. Link to comment Share on other sites More sharing options...
TehWhale Posted October 19, 2008 Share Posted October 19, 2008 It would help if you gave me your whole code instead of one function and your main loop. Link to comment Share on other sites More sharing options...
grunewald6 Posted October 19, 2008 Author Share Posted October 19, 2008 Can do. expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> ;Installs resource files FileInstall ("printmig.exe", @TempDir & "\") ;GUI $Form1 = GUICreate("Profile Backup and Restore", 280, 149, 193, 125) $Label = GUICtrlCreateLabel("Enter the Username", 24, 11, 122, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Input = GUICtrlCreateInput("", 17, 36, 137, 21) $Label2 = GUICtrlCreateLabel("Include Printers?", 24, 71, 100, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Printers = GUICtrlCreateCheckbox("", 130, 69, 20, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $NBMS = GUICtrlCreateRadio("NBMS", 192, 36, 57, 17) GUICtrlSetState(-1, $GUI_CHECKED) $NBES = GUICtrlCreateRadio("NBES", 192, 60, 57, 17) $Amqui = GUICtrlCreateRadio("AMQUI", 192, 84, 57, 17) $Label2 = GUICtrlCreateLabel("What school?", 176, 11, 85, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Backup = GUICtrlCreateButton("Backup", 8, 102, 73, 33, 0) $Restore = GUICtrlCreateButton("Restore", 89, 102, 73, 33, 0) GUISetState(@SW_SHOW) ;Main program While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Backup Checkuser () Backup () ;Will Run Backup Function Exit Case $msg = $Restore Restore () ;Will Run Restore Function exit EndSelect WEnd ;Functions Func Backup () $username = guictrlread($input) Select Case GUICtrlRead($NBMS) = $GUI_CHECKED $server = "\\600npsdtconsole\backup$\" Case GUICtrlRead($NBES) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" Case GUICtrlRead($Amqui) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" EndSelect ProgressOn("Backing up System...", "Copying Desktop Files", "Running...", -1, -1, 18); Create a Progress bar. WinSetOnTop ("Backing", "", 1) DirCopy ("c:/documents and settings/" & $username & "/desktop", $server & $username & "\Desktop", 9) ProgressSet(12.5, "", "Copying My Documents"); Advance the Progress Bar. DirCopy ("c:/documents and settings/" & $username & "/My Documents", $server & $username & "\My Documents", 9) ProgressSet(25, "", "Copying Favorites"); Advance the Progress Bar. DirCopy ("c:/documents and settings/" & $username & "/Favorites", $server & $username & "\Favorites", 9) ProgressSet(37.7, "", "Copying Examview Banks"); Advance the Progress Bar. DirCopy ("c:/program files/examview/banks", $server & $username & "\My Documents\Examview Banks", 9) ProgressSet(50, "", "Copying Examview Tests"); Advance the Progress Bar. DirCopy ("c:/program files/examview/tests", $server & $username & "\My Documents\Examview Tests", 9) ProgressSet(62.5, "", "Copying Outlook Files"); Advance the Progress Bar. FileCopy ("C:/Documents and Settings/" & $username & "/Local Settings/Application Data/Microsoft/Outlook/*.pst", $server & $username & "\My Documents\", 9) ProgressSet(75, "", "Copying Outlook Files"); Advance the Progress Bar. FileCopy ("C:/Documents and Settings/" & $username & "/Application Data/Microsoft/Outlook/*.nk2", $server & $username & "\", 9) If GUICtrlRead($Printers) = $GUI_CHECKED Then ProgressSet(87.5, "", "Copying Printers"); Advance the Progress Bar. _RunDOS ("%temp%\printmig -b " & $server & $username & "\printerbackup.cab") EndIf ProgressSet(100, "Done", "Backup Complete"); Advance the Progress Bar. Sleep(2000); Wait 2 seconds. ProgressOff(); Close progress window. FileDelete (@TempDir & "\printmig.exe") EndFunc Func Restore () $username = guictrlread($input) Select Case GUICtrlRead($NBMS) = $GUI_CHECKED $server = "\\600npsdtconsole\backup$\" Case GUICtrlRead($NBES) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" Case GUICtrlRead($Amqui) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" EndSelect ProgressOn("Restoring System...", "Restoring Desktop Files", "Running...", -1, -1, 18); Create a Progress bar. WinSetOnTop ("Restoring", "", 1) DirCopy ($server & $username & "\Desktop", "c:/documents and settings/" & $username & "/desktop/", 9) ProgressSet(20, "", "Restoring My Documents"); Advance the Progress Bar. DirCopy ($server & $username & "\My Documents", "c:/documents and settings/" & $username & "/My Documents/", 9) ProgressSet(40, "", "Restoring Favorites"); Advance the Progress Bar. DirCopy ($server & $username & "\Favorites", "c:/documents and settings/" & $username & "/Favorites/", 9) ProgressSet(60, "", "Restoring Outlook Files"); Advance the Progress Bar. FileCopy ($server & $username & "\*.nk2", "C:/Documents and Settings/" & $username & "/Application Data/Microsoft/Outlook/", 9) If FileExists ($server & $username & "\printerbackup.cab") then ProgressSet(80, "", "Restoring Printers"); Advance the Progress Bar. _RunDOS ("%temp%\printmig -r " & $server & $username & "\printerbackup.cab") EndIf ProgressSet(100, "Done", "Restore Complete"); Advance the Progress Bar. Sleep(2000); Wait 2 seconds. ProgressOff(); Close progress window. FileDelete (@TempDir & "\printmig.exe") EndFunc Func CheckUser () $username = guictrlread($input) If not FileExists("C:\documents and settings\" & $username) Then MsgBox(0, "Error", "Check spelling. That user profile is not on this computer.") EndIf EndFunc Link to comment Share on other sites More sharing options...
TehWhale Posted October 19, 2008 Share Posted October 19, 2008 This will work, but just a note, this script will not work on Vista because vista does not use C:\Documents and Settings\ it uses, C:\Users\. expandcollapse popup#include <GUIConstants.au3> #include <Process.au3> ;Installs resource files FileInstall("printmig.exe", @TempDir & "\") ;GUI $Form1 = GUICreate("Profile Backup and Restore", 280, 149, 193, 125) $Label = GUICtrlCreateLabel("Enter the Username", 24, 11, 122, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Input = GUICtrlCreateInput("", 17, 36, 137, 21) $Label2 = GUICtrlCreateLabel("Include Printers?", 24, 71, 100, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Printers = GUICtrlCreateCheckbox("", 130, 69, 20, 20) GUICtrlSetState(-1, $GUI_CHECKED) $NBMS = GUICtrlCreateRadio("NBMS", 192, 36, 57, 17) GUICtrlSetState(-1, $GUI_CHECKED) $NBES = GUICtrlCreateRadio("NBES", 192, 60, 57, 17) $Amqui = GUICtrlCreateRadio("AMQUI", 192, 84, 57, 17) $Label2 = GUICtrlCreateLabel("What school?", 176, 11, 85, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Backup = GUICtrlCreateButton("Backup", 8, 102, 73, 33, 0) $Restore = GUICtrlCreateButton("Restore", 89, 102, 73, 33, 0) GUISetState(@SW_SHOW) ;Main program While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Backup If Not CheckUser() = 0 Then Backup() Exit EndIf Case $msg = $Restore Restore() ;Will Run Restore Function Exit EndSelect WEnd ;Functions Func Backup() $username = GUICtrlRead($Input) Select Case GUICtrlRead($NBMS) = $GUI_CHECKED $server = "\\600npsdtconsole\backup$\" Case GUICtrlRead($NBES) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" Case GUICtrlRead($Amqui) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" EndSelect ProgressOn("Backing up System...", "Copying Desktop Files", "Running...", -1, -1, 18); Create a Progress bar. WinSetOnTop("Backing", "", 1) DirCopy("c:/documents and settings/" & $username & "/desktop", $server & $username & "\Desktop", 9) ProgressSet(12.5, "", "Copying My Documents"); Advance the Progress Bar. DirCopy("c:/documents and settings/" & $username & "/My Documents", $server & $username & "\My Documents", 9) ProgressSet(25, "", "Copying Favorites"); Advance the Progress Bar. DirCopy("c:/documents and settings/" & $username & "/Favorites", $server & $username & "\Favorites", 9) ProgressSet(37.7, "", "Copying Examview Banks"); Advance the Progress Bar. DirCopy("c:/program files/examview/banks", $server & $username & "\My Documents\Examview Banks", 9) ProgressSet(50, "", "Copying Examview Tests"); Advance the Progress Bar. DirCopy("c:/program files/examview/tests", $server & $username & "\My Documents\Examview Tests", 9) ProgressSet(62.5, "", "Copying Outlook Files"); Advance the Progress Bar. FileCopy("C:/Documents and Settings/" & $username & "/Local Settings/Application Data/Microsoft/Outlook/*.pst", $server & $username & "\My Documents\", 9) ProgressSet(75, "", "Copying Outlook Files"); Advance the Progress Bar. FileCopy("C:/Documents and Settings/" & $username & "/Application Data/Microsoft/Outlook/*.nk2", $server & $username & "\", 9) If GUICtrlRead($Printers) = $GUI_CHECKED Then ProgressSet(87.5, "", "Copying Printers"); Advance the Progress Bar. _RunDOS("%temp%\printmig -b " & $server & $username & "\printerbackup.cab") EndIf ProgressSet(100, "Done", "Backup Complete"); Advance the Progress Bar. Sleep(2000); Wait 2 seconds. ProgressOff(); Close progress window. FileDelete(@TempDir & "\printmig.exe") EndFunc ;==>Backup Func Restore() $username = GUICtrlRead($Input) Select Case GUICtrlRead($NBMS) = $GUI_CHECKED $server = "\\600npsdtconsole\backup$\" Case GUICtrlRead($NBES) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" Case GUICtrlRead($Amqui) = $GUI_CHECKED $server = "\\007npsltconsole\backup$\" EndSelect ProgressOn("Restoring System...", "Restoring Desktop Files", "Running...", -1, -1, 18); Create a Progress bar. WinSetOnTop("Restoring", "", 1) DirCopy($server & $username & "\Desktop", "c:/documents and settings/" & $username & "/desktop/", 9) ProgressSet(20, "", "Restoring My Documents"); Advance the Progress Bar. DirCopy($server & $username & "\My Documents", "c:/documents and settings/" & $username & "/My Documents/", 9) ProgressSet(40, "", "Restoring Favorites"); Advance the Progress Bar. DirCopy($server & $username & "\Favorites", "c:/documents and settings/" & $username & "/Favorites/", 9) ProgressSet(60, "", "Restoring Outlook Files"); Advance the Progress Bar. FileCopy($server & $username & "\*.nk2", "C:/Documents and Settings/" & $username & "/Application Data/Microsoft/Outlook/", 9) If FileExists($server & $username & "\printerbackup.cab") Then ProgressSet(80, "", "Restoring Printers"); Advance the Progress Bar. _RunDOS("%temp%\printmig -r " & $server & $username & "\printerbackup.cab") EndIf ProgressSet(100, "Done", "Restore Complete"); Advance the Progress Bar. Sleep(2000); Wait 2 seconds. ProgressOff(); Close progress window. FileDelete(@TempDir & "\printmig.exe") EndFunc ;==>Restore Func CheckUser() $username = GUICtrlRead($Input) If Not FileExists("C:\documents and settings\" & $username) Then MsgBox(0, "Error", "Check spelling. That user profile is not on this computer.") Return 0 EndIf Return 1 EndFunc ;==>CheckUser Link to comment Share on other sites More sharing options...
Valuater Posted October 19, 2008 Share Posted October 19, 2008 Use this to query checkboxes and radios \Select Case _IsChecked($NBMS) $server = "\\600npsdtconsole\backup$\" Case _IsChecked($NBES) $server = "\\007npsltconsole\backup$\" Case _IsChecked($Amqui) $server = "\\007npsltconsole\backup$\" EndSelect Func _IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked 8) Link to comment Share on other sites More sharing options...
grunewald6 Posted October 19, 2008 Author Share Posted October 19, 2008 Thanks TehWhale. That worked perfectly. Thanks to both on simplifying and notation tips. Still learning this but it is actually pretty fun. This forum has been indispensible. 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