ACalcutt Posted August 9, 2005 Posted August 9, 2005 I am making a script to get a pc ready for sysprep by installing the software and changing windows setttings.... the program uses an INI filethe autoit scipt and all install files are located on a cd...the script first check to see if settings.ini is on the c: drive....if not it copies it to that DIR Quote DIM $settings = @HomeDrive & "\settings.ini";COPY INI FILE TO HOMEDIR DRIVE IF IT DOES NOT EXISTIF FileExists ($settings) = 0 ThenFileCopy(@WorkingDir & "\settings.ini", $settings, 0)ENDIFthis seems to work fine...but when my script restarts or logs off it seems to have problems with the settings. for example...part of my script changes the backround..but after a restart it does not like to type the full path...if i close the autoit program and restart it it works fine...in the background example i am getting C:\Windows\web\Wallpaper\....but it should be C:\Windows\web\Wallpaper\Desktop1.jpg ....this script works fine if the computer doesn't restart/logoff....its only when a previous item restarts the script...and if i close the script and restart again(the program is made to start where it left off) it works fine... It seems with a problem reading the ini file....but the program also keeps what it has already done in the ini so it knows what the next step is....so its a weird problem to meI also had a strange problem that makes me think maybe its something with the cdrom...mcafee setup started and then told me it could not find a file....(again after a reboot)...then i closed and restared the script and it went fine...This problem has occured on my test computer at home and my test computer at work...2 completely different systems Quote DIM $system_image = ""DIM $cd_image = IniRead($settings, "Background", "CD_Image", "")DIM $specified_image = IniRead($settings, "Background", "Specify_Image_Name", "")DIM $specified_image_dir = IniRead($settings, "Background", "Specify_Image_DIR", "")DIM $specified_fullpath = $specified_image_dir & "\" & $specified_imageRun(@comspec & ' /c ' & 'desk.cpl')WinWaitActive("Display Properties")WHILE 1 If WinExists("Display Properties", "Desktop") = 1 Then EXITLOOP ENDIF If WinExists("Display Properties", "Desktop") = 0 Then WinWaitActive("Display Properties") Send("^{TAB}") ENDIF SLEEP(500)WEND;------------------------------------------------Set Background-------------------------------------ControlClick("Display Properties", "", "Button1")IF FileExists ($specified_fullpath) THEN $system_image = @WindowsDir & "\web\Wallpaper\" & $specified_image SLEEP(1000) FileCopy($specified_fullpath, $system_image, 1) IF IniRead($settings, "Background", "Del_Image", "0") = "1" THEN FileDelete($specified_fullpath) ENDIFELSE IF FileExists ($cd_image) THEN $system_image = @WindowsDir & "\web\Wallpaper\" & $cd_image FileCopy ( $cd_image, $system_image, 1) ELSE msgbox(0,"Error","No Background Image Found") ENDIFENDIFWinWaitActive("Browse")IF $system_image <> "" THEN WinWaitActive("Browse") ;ControlSetText("Browse", "", "Edit1", $system_image) WHILE 1 ControlFocus ( "Browse", "", "Edit1" ) Send($system_image) IF ControlGetText ( "Browse", "", "Edit1" ) <> "" THEN ExitLOOP ENDIF WEND ControlClick("Browse", "", "Button2")ELSE WinClose("Browse")ENDIFWinWaitActive("Display Properties")SLEEP(1000) Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature
ACalcutt Posted August 9, 2005 Author Posted August 9, 2005 (edited) Here is the main EXE script..... Quote ; ----------------------------------------------------------------------------;; AutoIt Version: 3.1.0; Author:Andrew Calcutt;; Script Function:; Auto-Sysprep Utility;;-----------------------------------------------------------------------------DIM $flag=0, $shutdown="RUN";-----------------------------------------------------------------------------#include <GUIConstants.au3>; ----------------------------------------------------------------------------DIM $settings = @HomeDrive & "\settings.ini";COPY INI FILE TO HOMEDIR DRIVE IF IT DOES NOT EXISTIF FileExists ($settings) = 0 ThenFileCopy(@WorkingDir & "\settings.ini", $settings, 0)ENDIFFileSetAttrib ( $settings, "-R+N")DIM $logonuser1 = IniRead ($settings, "Script_Settings", "Admin_Username", "Administrator" ) DIM $logonpass1 = IniRead ($settings, "Script_Settings", "Admin_Password", "" )DIM $logonuser2 = IniRead ($settings, "Script_Settings", "Sysprep_Username", "sysprep" ) DIM $logonpass2 = IniRead ($settings, "Script_Settings", "Sysprep_Password", "Password1" );RUN GUI UNLESS SPECIFIEDIF IniRead($settings, "Script_Settings", "Run_GUI", "1") = 1 THEN GUICreate ( "Automatic System Preperation - "& @OSVersion , "320" , "400" ) GUISetState (@SW_SHOW) $mcinstall = GUICtrlCreateCheckbox ("Install McAffe", 10, 10, 170, 20) $spinstall = GUICtrlCreateCheckbox ("Install Sophos", 10, 30, 170, 20) $vpninstall = GUICtrlCreateCheckbox ("Install VPN", 10, 50, 170, 20) $offinstall = GUICtrlCreateCheckbox ("Install Office", 10, 70, 170, 20) $vissettings = GUICtrlCreateCheckbox ("Set Visual Style", 10, 90, 300, 20) $copyprofile = GUICtrlCreateCheckbox ("Copy Profile(Logon Information Required)", 10, 110, 300, 20) $waitupdate = GUICtrlCreateCheckbox ("Wait to Update", 10, 130, 300, 20) $cleansms = GUICtrlCreateCheckbox ("Clean SMS", 10, 150, 300, 20) $mcguid = GUICtrlCreateCheckbox ("Remove McAffe GUID", 10, 170, 300, 20) $defragment = GUICtrlCreateCheckbox ("Defragment", 10, 190, 300, 20) $runsysprep = GUICtrlCreateCheckbox ("Run Sysprep", 10, 210, 300, 20) GUICtrlCreateLabel ( "Default Admin User", 10, 280, 120, 15) $username = GUICtrlCreateInput ( $logonuser1, 10, 295, 120, 20) GUICtrlCreateLabel ( "Default Admin Pass", 10, 320, 120, 15) $password = GUICtrlCreateInput ( $logonpass1, 10, 335, 120, 20) GUICtrlCreateLabel ( "Sysprep User", 180, 280, 120, 15) $username2 = GUICtrlCreateInput ( $logonuser2, 180, 295, 120, 20) GUICtrlCreateLabel ( "Sysprep Pass(STRONG)", 180, 320, 120, 15) $password2 = GUICtrlCreateInput ( $logonpass2, 180, 335, 120, 20) GUICtrlCreateGroup ("Logon Information", 5, 260, 310, 100) ;BOTTOM BUTTONS $okbutton = GuiCtrlCreateButton ("OK",20,365,70,20) $canclebutton= GuiCtrlCreateButton ("Cancle",210,365,70,20) ; GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $okbutton IniWrite ( $settings, "Script_Settings", "Admin_Username", GUICtrlRead($username)) IniWrite ( $settings, "Script_Settings", "Admin_Password", GUICtrlRead($password)) IniWrite ( $settings, "Script_Settings", "Sysprep_Username", GUICtrlRead($username2)) IniWrite ( $settings, "Script_Settings", "Sysprep_Password", GUICtrlRead($password2)) ;CHOICES IF GUICtrlRead($mcinstall) = 1 Then IniWrite ( $settings, "Script_Settings", "Install_McAfee", "1" ) ENDIF IF GUICtrlRead($vissettings) = 1 Then IniWrite ( $settings, "Script_Settings", "Set_Visual_Settings", "1" ) ENDIF IF GUICtrlRead($vpninstall) = 1 Then IniWrite ( $settings, "Script_Settings", "Install_VPN", "1" ) ENDIF IF GUICtrlRead($offinstall) = 1 Then IniWrite ( $settings, "Script_Settings", "Install_Office", "1" ) ENDIF IF GUICtrlRead($copyprofile) = 1 Then IniWrite ( $settings, "Script_Settings", "Copy_Profile", "1" ) ENDIF IF GUICtrlRead($cleansms) = 1 Then IniWrite ( $settings, "Script_Settings", "Clean_SMS", "1" ) ENDIF IF GUICtrlRead($mcguid) = 1 Then IniWrite ( $settings, "Script_Settings", "Remove_McAfee_GUID", "1" ) ENDIF IF GUICtrlRead($waitupdate) = 1 Then IniWrite ( $settings, "Script_Settings", "Wait_Updates", "1" ) ENDIF IF GUICtrlRead($defragment) = 1 Then IniWrite ( $settings, "Script_Settings", "Defrag", "1" ) ENDIF IF GUICtrlRead($runsysprep) = 1 Then IniWrite ( $settings, "Script_Settings", "Run_Sysprep", "1" ) ENDIF ;EXIT GUI IniWrite ( $settings, "Script_Settings", "Run_GUI", "0" ) ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $canclebutton ExitLoop EndSelect WendGUIDelete()ENDIF ;--------------------------------END GUI STUFF-----------------------------------------------------DIM $logonuser1 = IniRead ($settings, "Script_Settings", "Admin_Username", "Administrator" ) DIM $logonpass1 = IniRead ($settings, "Script_Settings", "Admin_Password", "" )DIM $logonuser2 = IniRead ($settings, "Script_Settings", "Sysprep_Username", "sysprep" ) DIM $logonpass2 = IniRead ($settings, "Script_Settings", "Sysprep_Password", "Password1" )DIM $logonuser = $logonuser1DIM $logonpass = $logonpass1;***Removes initail user***IF IniRead ($settings, "Script_Settings", "Delete_Start_User", "0" ) = 1 THEN IF @UserName <> $logonuser1 then IniWrite ( $settings, "Script_Settings", "Delete_User", @Username ) IniWrite ( $settings, "Script_Settings", "Delete_Start_User", "2" ) $shutdown = "LOGOFF" ELSE IniWrite ( $settings, "Script_Settings", "Delete_Start_User", "0" ) ENDIFENDIFIF $shutdown = "RUN" THEN IF IniRead ($settings, "Script_Settings", "Delete_Start_User", "0" ) = 2 THEN $profileuser = IniRead ($settings, "Script_Settings", "Delete_User", "" ) #include <remove_profile.au3> $logonuser = IniRead ($settings, "Script_Settings", "Delete_User", "" ) #include <remove_user.au3> $logonuser = $logonuser1 IniWrite ( $settings, "Script_Settings", "Delete_Start_User", "0" ) ENDIF ;*** INSTALLS MCAFEE *** IF IniRead ($settings, "Script_Settings", "Install_McAfee", "0" ) = 1 THEN #include <mcafee.au3> IniWrite ( $settings, "Script_Settings", "Install_McAfee", "2" ) $shutdown = "REBOOT" ENDIF ;INSTALL VPN SOFTWARE IF IniRead ($settings, "Script_Settings", "Install_VPN", "0" ) = 1 THEN #include <vpn.au3> IniWrite ( $settings, "Script_Settings", "Install_VPN", "2" ) $shutdown = "REBOOT" ENDIF ;INSTALL OFFICE IF IniRead ($settings, "Script_Settings", "Install_Office", "0" ) = 1 THEN ;#include <office.au3> #include <Auto_Install_Office.au3> IniWrite ( $settings, "Script_Settings", "Install_Office", "2" ) $shutdown = "REBOOT" ENDIFENDIFIF $shutdown = "RUN" THEN ;*** SET VISUAL SETTINGS *** IF IniRead ($settings, "Script_Settings", "Set_Visual_Settings", "0" ) = 1 THEN #include <vis_settings.au3> IF IniRead ($settings, "Script_Settings", "Install_Office", "0" ) = 2 THEN IF IniRead ($settings, "OFFICE", "Add_Office_Toolbar", "0" ) = 1 THEN $toolbardir=@ProgramsCommonDir & "\Microsoft Office" #include <toolbar.au3> ENDIF ENDIF #include <desktop.au3> $regsearchstart = "My Computer\HKEY_USERS" $regsearch = "S-1-5-21" #include <findreg.au3> $HKUS1521 = ClipGet ( ) #include <Start_Menu.au3> #include <taskbar.au3> ProcessClose("explorer.exe") Run("explorer.exe") IniWrite ( $settings, "Script_Settings", "Set_Visual_Settings", "2" ) ENDIFENDIFIF $shutdown = "RUN" THEN;*** MAKE SYSPREP USER - RESTART FOR COPY PROFILE *** IF IniRead ($settings, "Script_Settings", "Copy_Profile", "0" ) = 1 THEN $logonuser = $logonuser2 $logonpass = $logonpass2 #include <new_user.au3> IniWrite ( $settings, "Script_Settings", "Copy_Profile", "2" ) $shutdown = "LOGOFF" ENDIF ENDIFIF $shutdown = "RUN" THEN ;*** COPY PROFILE *** IF IniRead ($settings, "Script_Settings", "Copy_Profile", "0" ) = 2 THEN #include <copy_profile.au3> $logonuser = $logonuser1 $logonpass = $logonpass1 IniWrite ( $settings, "Script_Settings", "Copy_Profile", "3" ) $shutdown = "LOGOFF" ENDIFENDIFIF $shutdown = "RUN" THEN;*** Remove sysprep user/profile *** IF IniRead ($settings, "Script_Settings", "Copy_Profile", "0" ) = 3 THEN $profileuser = $logonuser2 #include <remove_profile.au3> $logonuser = $logonuser2 $logonpass = $logonpass2 #include <remove_user.au3> IniWrite ( $settings, "Script_Settings", "Copy_Profile", "2" ) ENDIF;*** WAIT FOR UPDATES/INSTALLS *** IF IniRead ($settings, "Script_Settings", "Wait_Updates", "0" ) = 1 THEN msgbox(0,"Waiting", "Install updates or extra software - HIT OK WHEN DONE - This window will start on next boot if you need to restart") ENDIF ;*** CLEAN SMS *** IF IniRead ($settings, "Script_Settings", "Clean_SMS", "0" ) = 1 THEN #include <clean_sms.au3> IniWrite ( $settings, "Script_Settings", "Clean_SMS", "2" ) ENDIF ;*** REMOVE McAfee GUID *** IF IniRead ($settings, "Script_Settings", "Remove_McAfee_GUID", "0" ) = 1 THEN RunWait("net stop McAfeeFramework") RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent", "TestKeyAgentGUID") IniWrite ( $settings, "Script_Settings", "Remove_McAfee_GUID", "2" ) ENDIF ;*** DEFRAGMENT *** IF IniRead ($settings, "Script_Settings", "Defrag", "0" ) = 1 THEN #include <defrag.au3> IniWrite ( $settings, "Script_Settings", "Defrag", "2" ) ENDIF ;*** SYSPREP *** IF IniRead ($settings, "Script_Settings", "Run_Sysprep", "0" ) = 1 THEN FileDelete ($settings) RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Continue_Sysprep") IF @OSVersion = "WIN_XP" THEN DirCopy ( "sysprep\WinXP\sysprep", "c:\sysprep" , 1 ) ENDIF IF @OSVersion = "WIN_2000" THEN DirCopy ( "sysprep\Win2K\sysprep", "c:\sysprep" , 1 ) ENDIF Run("c:\sysprep\sysprep.exe") ENDIFENDIF ;--------------------------------Shutdown stuff--------------------------------------------------------------------------;LOGOFFIF $shutdown = "LOGOFF" THENRegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Continue_Sysprep", "REG_SZ", @AutoItExe)#include <logon.au3>Shutdown (0)ENDIF;REBOOTIF $shutdown = "REBOOT" THENRegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Continue_Sysprep", "REG_SZ", @AutoItExe)#include <logon.au3>Shutdown (2)ENDIFlogon.au3 Quote RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1" )RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", $logonuser )RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", $logonpass );FIX NO PASSWORD PROBLEMIF $logonuser = "" Then RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "" )ENDIFRegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon", "REG_SZ", "1" ) Edited August 9, 2005 by ACalcutt Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature
GaryFrost Posted August 9, 2005 Posted August 9, 2005 post in support SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
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