;-----------------------------------------------------------------------------
; AutoIt Version: 3.1.1.100
; Author:Andrew Calcutt 	Last Edited:1/8/2006
; Script Function:	Functions
;-----------------------------------------------------------------------------
;_no_gui.exe Functions
;-----------------------------------------------------------------------------
;	_FindReg("Start Search Key", "String to find"[, "String occurance"])
;	_Logon($action, $logonuser = "", $logonpass = "", $startprogram = "")
;	_Shutdown($shutdown, $action, $logonuser = "", $logonpass = "", $startprogram = "")
;	_User($action, $user, $pass, $level)
;	_Profile($action, $user)
;	_Progress_Ref($action)
;	_DeleteINI()
;	_Desktop()
;	_FolderOptions($settings, $HKUS1521)
;	_StartMenu($settings, $HKUS1521)
;	_Taskbar($settings, $HKUS1521)
;	_TaskToolbar($toolbardir)
;	_VisualSettings()
;	_IniReadRegWrite($settings, $section1, $key1, $reg1, $reg2, $regtype, $regvalue1, $regvalue2)
;	_IniReadRegWrite2($settings, $section1, $key1, $reg1, $reg2, $regtype, $regvalue1, $regvalue2, $regvalue3[, $regvalue4])
;	_DesktopButton($settings, $section1, $key1, $title, $button)
;	_RunNetSupport($fullpath_exe, $netuser, $netpass, $netdom)
;-----------------------------------------------------------------------------
;PrepSys.exe Functions
;-----------------------------------------------------------------------------
;	_Set_INI_Settings()
;	_Sophos_State()
;	_McAfee_State()
;	_Office_State()
;	_Sysprep_User_State()
;	_Folder_Options_State()
;	_VisSettings_State()
;	_StartMenuState()
;	_StartMenuSwitch()
;	_IniReadCheckbox_Ran($settings, ByRef $id, $name, $section1, $key1, $section2, $key2, $CR, $CT, $CW, $CH, $RR)
;	_LabeledCombo($settings, ByRef $id, ByRef $id2, $label, $section1, $key1, $item0, $item1, $item2, $R, $T, $W, $H, $LR, $LT, $LW, $LH)
;	_IniWriteCheckbox($settings, ByRef $id, $section1, $key1, $progress = "", $section2 = "", $key2 = "", $key3 = "", $key4 = "")
;	_IniWriteCombo($settings, ByRef $id, $section1, $key1)
;	_FileBrowse($default, ByRef $input, ByRef $browse, $R, $T, $W, $H, $BR, $BW)
;	_FileBrowseSet(ByRef $exe, $label)
;	_State(Const $state, Const $1, Const $2, Const $3, Const $4, Const $5, Const $6, Const $7, Const $8, Const $9, Const $10)
;	_ExeLocationWrite(Const $orig, Const $file, Const $settings, $section1, $key1)
;	_NetworkLogin()
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

;<-- ######################################################### _NO_GUI.EXE FUNC ######################################################### -->


Func _FindReg($regsearchstart, $regsearch, $key = 1)
	While 1
		$result = RegEnumKey($regsearchstart, $key)
		If @error = -1 Then
			MsgBox(0, "Error", "Registry key Not Found")
			Exit
		EndIf
		If StringInStr($result, $regsearch) = 1 Then
			If StringInStr($result, "_Classes", 0) Then
				ExitLoop
			EndIf
		EndIf
		$key = $key + 1
	WEnd
	$result = StringTrimRight($result, 8)
	
	Return $result
EndFunc   ;==>_FindReg


Func _Logon($action, $logonuser = "", $logonpass = "", $startprogram = "")
	Select
		Case $action = "REMOVE"
			If IniRead($settings, "Program_Use_Only", "legalnoticecaption", "") <> "" Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticecaption", "REG_SZ", IniRead($settings, "Program_Use_Only", "legalnoticecaption", ""))
			If IniRead($settings, "Program_Use_Only", "legalnoticetext", "") <> "" Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticetext", "REG_SZ", IniRead($settings, "Program_Use_Only", "legalnoticetext", ""))
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "0")
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", "")
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "")
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon", "REG_SZ", "0")
			RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Continue_Sysprep")
		Case $action = "ADD"
			If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticecaption") <> "" Then IniWrite($settings, "Program_Use_Only", "legalnoticecaption", RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticecaption"))
			If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticetext") <> "" Then IniWrite($settings, "Program_Use_Only", "legalnoticetext", RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticetext"))
			RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticecaption")
			RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system", "legalnoticetext")
			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)
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", @ComputerName)
			;FIX NO PASSWORD PROBLEM
			If $logonpass = "" Then
				RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "")
			EndIf
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon", "REG_SZ", "1")
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Continue_Sysprep", "REG_SZ", """" & $startprogram & """")
	EndSelect
EndFunc   ;==>_Logon


Func _Shutdown($shutdown, $action, $logonuser = "", $logonpass = "", $startprogram = "")
	Select
		Case $shutdown = "LOGOFF"
			_Logon($action, $logonuser, $logonpass, $startprogram)
			Shutdown(0)
			Exit
		Case $shutdown = "REBOOT"
			_Logon($action, $logonuser, $logonpass, $startprogram)
			Shutdown(2)
			Exit
	EndSelect
EndFunc   ;==>_Shutdown

Func _User($action, $user, $pass, $level)

	Select
		Case $action = "ADD"
			Run(@ComSpec & ' /c ' & 'compmgmt.msc')
			WinWaitActive("Computer Management")

			;SELECT USERS GROUP
			BlockInput(1)
			Send("l")
			Send("{RIGHT}")
			Send("{DOWN}")

			;NEW USER
			Send("!an")
			WinWaitActive("New User")
			ControlSetText("New User", "", "Edit1", $user)
			ControlSetText("New User", "", "Edit4", $pass)
			ControlSetText("New User", "", "Edit5", $pass)
			ControlClick("New User", "", "Button1")
			ControlClick("New User", "", "Button5")

			While 1
			If ControlCommand("New User", "", "Button1", "IsChecked", "") = 1 Then
				ExitLoop
			EndIf
			Sleep(200)
			WEnd
			WinClose("New User")
			WinClose("Computer Management")
			_User("SET", $user, $pass, $level)
		Case $action = "REMOVE"
			Run("rundll32.exe netplwiz.dll,UsersRunDll")
			While 1
				If WinExists("User Accounts") Then
					WinActivate("User Accounts")
					ExitLoop
				EndIf
			WEnd
			$deluser = -1
			While $deluser = -1
				Sleep(500)
				$deluser = ControlListView("User Accounts", "", "SysListView321", "FindItem", $user)
			WEnd
			ControlListView("User Accounts", "", "SysListView321", "Select", $deluser)
			ControlClick("User Accounts", "", "Button3")
			WinWaitActive("User Accounts", "You chose to remove")
			ControlClick("User Accounts", "You chose to remove", "Button1")
			WinWaitActive("User Accounts", "users")
	Case $action = "SET"
			Run("rundll32.exe netplwiz.dll,UsersRunDll")
			While 1
				If WinExists("User Accounts") Then
					WinActivate("User Accounts")
					ExitLoop
				EndIf
			WEnd
			$makeadmin = -1
			While $makeadmin = -1
				Sleep(500)
				$makeadmin = ControlListView("User Accounts", "", "SysListView321", "FindItem", $user)
			WEnd
			ControlListView("User Accounts", "", "SysListView321", "Select", $makeadmin)
			ControlClick("User Accounts", "", "Button4")
			;SET PROPERTIES WINDOW NAME
			$propertieswinname = @ComputerName & "\" & $user & " Properties"
			WinWaitActive($propertieswinname)
			;SWITCH TAB
			Send("^{TAB}")
			;Choose Administrators Group
			ControlClick($propertieswinname, "", "Button3")
			ControlCommand($propertieswinname, "", "ComboBox1", "SelectString", $level)
			;APPLY
			ControlClick($propertieswinname, "", "Button6")
			;CLOSE WINDOW
			WinClose($propertieswinname)
	EndSelect
	WinClose("User Accounts")
EndFunc   ;==>_User

Func _Profile($action, $user)
	;LOAD SYSTEM PROPERTIES - Advanced tab
	Run("RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3")
	;CLICK USER PROFILE SETTINGS
	While 1
		If WinExists("System Properties") Then
			WinActivate("System Properties")
			ControlClick("System Properties", "Advanced", "Button4")
			ExitLoop
		EndIf
	WEnd
	While 1
		If WinExists("User Profiles") Then
			WinActivate("User Profiles")
			ExitLoop
		EndIf
	WEnd
	;PICK User
	$pickprofile = @ComputerName & "\" & $user
	$pickprofile = ControlListView("User Profiles", "", "SysListView321", "FindItem", $pickprofile)
	ControlListView("User Profiles", "", "SysListView321", "Select", $pickprofile)
	
	Select
		Case $action = "COPY"
			ControlClick("User Profiles", "", "Button3")
			While 1
				If WinExists("Copy To") Then
					WinActivate("Copy To")
					;SET DESTINATION
					$copy_to = @HomeDrive & "\Documents and Settings\Default User"
					ControlSetText("Copy To", "", "Edit1", $copy_to)
					ControlClick("Copy To", "", "Button5")
					ExitLoop
				Else
					Sleep(200)
				EndIf
			WEnd
			While 1
				If WinExists("Confirm Copy") Then
					WinActivate("Confirm Copy")
					ControlClick("Confirm Copy", "", "Button1")
					ExitLoop
				Else
					Sleep(200)
				EndIf
			WEnd
			While 1
				If WinExists("Copy To") Then
					Sleep(500)
				Else
					ExitLoop
				EndIf
			WEnd
		Case $action = "REMOVE"
			;CLICK DELETE
			ControlClick("User Profiles", "", "Button2")
			WinWaitActive("Confirm Delete")
			ControlClick("Confirm Delete", "", "Button1")
	EndSelect
	
	While WinExists("User Profiles")
		WinClose("User Profiles")
	WEnd
	While WinExists("System Properties")
		WinClose("System Properties")
	WEnd
EndFunc   ;==>_Profile

Func _Progress_Ref($action)
	Select
		Case $action = "ADD"
			$progressref2 += 1
			IniWrite($settings, "Program_Use_Only", "Progress_Ref2", $progressref2)
		Case $action = "SHOW"
			$run_percent = ($progressref2 / $progressref) * 100
			GUICtrlSetData($action_progress, $run_percent)
	EndSelect
EndFunc   ;==>_Progress_Ref

Func _DeleteINI()
	If IniRead($settings, "Script_Settings", "Delete_INI", "0") = 1 And IniRead($settings, "Script_Settings", "Run_Sysprep", "0") = 0 Then
		$progressref2 += 1
		FileDelete($settings)
	EndIf
	If IniRead($settings, "Script_Settings", "Run_Sysprep", "0") = 1 And IniRead($settings, "Program_Use_Only", "Ran_Sysprep", "0") = 1 Then
		If IniRead($settings, "Script_Settings", "Delete_INI", "0") = 1 Then $progressref2 += 1
		FileDelete($settings)
	EndIf
EndFunc   ;==>_DeleteINI

Func _Defrag()
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.0
	; Author:Andrew Calcutt 	Date:08/09/2005
	; Script Function: Defragments Computer
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	Run(@ComSpec & ' /c ' & 'dfrg.msc')
	WinWaitActive("Disk Defragmenter")
	
	ControlClick("Disk Defragmenter", "", "Button2")
	WinWaitActive("Disk Defragmenter", "Defragmentation is complete for:")
	ControlClick("Disk Defragmenter", "", "Button5")
	WinClose("Disk Defragmenter")
EndFunc   ;==>_Defrag

Func _Desktop()
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.1
	; Author:Andrew Calcutt 	Date:08/31/2005
	; Script Function: Sets Desktop Settings
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	Dim $system_image = ""
	Dim $cd_image = IniRead($settings, "Background", "CD_Image", "")
	Dim $cd_image_fullpath = $workingdir & $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_image
	;------------------------------------------------Set Background-------------------------------------
	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)
		EndIf
	Else
		If FileExists($cd_image_fullpath) Then
			$system_image = @WindowsDir & "\web\Wallpaper\" & $cd_image
			FileCopy($cd_image_fullpath, $system_image, 1)
		Else
			MsgBox(0, "Error", "No Background Image Found")
		EndIf
	EndIf
	If FileExists($system_image) Then
		RegWrite("HKCU\Control Panel\Desktop", "Wallpaper", "REG_SZ", $system_image)
		Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True")
	EndIf
	;---------------------------------------------Desktop Items -------------------------------------
	Run("RunDll32.exe shell32.dll,Control_RunDLL desk.cpl,,0") ;Display settings - desktop tab
	While 1
		If WinExists("Display Properties") Then
			WinActivate("Display Properties")
			ExitLoop
		EndIf
	WEnd
	WinWaitActive("Display Properties")
	ControlClick("Display Properties", "", "Button3")
	WinWaitActive("Desktop Items")
	_DesktopButton($settings, "Desktop_Items", "My_Documents", "Desktop Items", "Button2")
	_DesktopButton($settings, "Desktop_Items", "My_Computer", "Desktop Items", "Button3")
	_DesktopButton($settings, "Desktop_Items", "My_Network_Places", "Desktop Items", "Button4")
	_DesktopButton($settings, "Desktop_Items", "Internet_Explorer", "Desktop Items", "Button5")
	_DesktopButton($settings, "Desktop_Items", "Enable_Desktop_Cleanup", "Desktop Items", "Button9")
	;OK
	ControlClick("Desktop Items", "", "Button11")
	WinWaitActive("Display Properties")
	Send("!a")
	WinWaitActive("Display Properties")
	WinClose("Display Properties")
EndFunc   ;==>_Desktop

Func _FolderOptions($settings, $HKUS1521)
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.1
	; Author:Andrew Calcutt 	Date:12/17/2005
	; Script Function: Sets Folder Settings
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	$regkey = $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
	_IniReadRegWrite($settings, "Folder_Options", "SearchNetPrinters", $regkey, "NoNetCrawling", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Folder_Options", "DisplayFileSizeInFolderTips", $regkey, "FolderContentsInfoTip", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "SimpleViewInFolderListView", $regkey, "FriendlyTree", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "DisplaySystemFolderContents", $regkey, "WebViewBarricade", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "FullPathAddress", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState", "FullPathAddress", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "FullPathTitle", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState", "FullPath", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "FullPathTitle", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState", "Settings", "REG_BINARY", "0C0002000B01807C60000000", "0C0002000A01807C60000000")
	_IniReadRegWrite($settings, "Folder_Options", "CacheThumbnails", $regkey, "DisableThumbnailCache", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Folder_Options", "ShowHiddenFiles", $regkey, "Hidden", "REG_DWORD", "0x00000001", "0x00000002")
	_IniReadRegWrite($settings, "Folder_Options", "ShowFileExtensions", $regkey, "HideFileExt", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Folder_Options", "ShowHiddenSysFiles", $regkey, "ShowSuperHidden", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "LaunchWindowsInSeperateProcess", $regkey, "SeparateProcess", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "RememberFolderSettings", $regkey, "ClassicViewState", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Folder_Options", "RestoreWindowsAtLogon", $regkey, "PersistBrowsers", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "ControlPanelInMyComputer", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\HideMyComputerIcons", "{21EC2020-3AEA-1069-A2DD-08002B30309D}", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Folder_Options", "ShowCompressedFilesInColor", $regkey, "ShowCompColor", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "ShowDesktopFolderInfoPopop", $regkey, "ShowInfoTip", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "UseSimpleFileSharing", "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Lsa", "forceguest", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Folder_Options", "UseSimpleFileSharing", "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa", "forceguest", "REG_DWORD", "0x00000001", "0x00000000")
EndFunc   ;==>_FolderOptions

Func _StartMenu($settings, $HKUS1521)
	; ----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.0
	; Author:Andrew Calcutt 	Date:08/09/2005
	; Script Function: Set Start Menu Options
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	$regkey = $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
	;CLASSIC START MENU OR NEW START MENU
	_IniReadRegWrite($settings, "StartMenu", "Classic_Menu", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer", "ShellState", "REG_BINARY", "2400000033880000000000000000000000000000010000000D0000000000000000000000", "2400000033880000000000000000000000000000010000000D0000000000000002000000")
	
	If IniRead($settings, "StartMenu", "Classic_Menu", "0") = 1 Then
		_IniReadRegWrite($settings, "Classic_Menu_Options", "DisplayAdminTools", $regkey, "StartMenuAdminTools", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "DisplayFavories", $regkey, "StartMenuFavorites", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "DisplayLogOff", $regkey, "StartMenuLogoff", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "DisplayRun", $regkey, "StartMenuRun", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "EnableDRAGandDROP", $regkey, "StartMenuChange", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ExpandControlPanel", $regkey, "CascadeControlPanel", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ExpandMyDocuments", $regkey, "CascadeMyDocuments", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ExpandMyPictures", $regkey, "CascadeMyPictures", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ExpandNetworkConnections", $regkey, "CascadeNetworkConnections", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ExpandPrinters", $regkey, "CascadePrinters", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "ScrollPrograms", $regkey, "StartMenuScrollPrograms", "REG_SZ", "YES", "NO")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "UsePersonalizedMenus", $regkey, "IntelliMenus", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "Classic_Menu_Options", "EnableDragDrop", $regkey, "Start_EnableDragDrop", "REG_DWORD", "0x00000001", "0x00000000")
	Else
		_IniReadRegWrite($settings, "StartMenu", "ScrollPrograms", $regkey, "Start_ScrollPrograms", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "ShowHelp", $regkey, "Start_ShowHelp", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "ShowPrinters", $regkey, "Start_ShowPrinters", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "ShowRun", $regkey, "Start_ShowRun", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "ShowSearch", $regkey, "Start_ShowSearch", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "ShowSetProgramAccessAndDefaults", $regkey, "Start_ShowSetProgramAccessAndDefaults", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite($settings, "StartMenu", "StartMenuFavorites", $regkey, "StartMenuFavorites", "REG_DWORD", "0x00000001", "0x00000000")
		_IniReadRegWrite2($settings, "StartMenu", "ShowControlPanel", $regkey, "Start_ShowControlPanel", "REG_DWORD", "0x00000000", "0x00000001", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowMyComputer", $regkey, "Start_ShowMyComputer", "REG_DWORD", "0x00000000", "0x00000001", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowMyDocs", $regkey, "Start_ShowMyDocs", "REG_DWORD", "0x00000000", "0x00000001", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowMyMusic", $regkey, "Start_ShowMyMusic", "REG_DWORD", "0x00000000", "0x00000001", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowNetConn", $regkey, "Start_ShowNetConn", "REG_DWORD", "0x00000000", "0x00000001", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowAdminTools", $regkey, "Start_AdminToolsRoot", "REG_DWORD", "0x00000000", "0x00000000", "0x00000002")
		_IniReadRegWrite2($settings, "StartMenu", "ShowAdminTools", $regkey, "StartMenuAdminTools", "REG_DWORD", "0x00000000", "0x00000001", "0x00000001")
	EndIf
EndFunc   ;==>_StartMenu

Func _Taskbar($settings, $HKUS1521)
	; ----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.0
	; Author:Andrew Calcutt 	Date:08/09/2005
	; Script Function: Sets Taskbar Options
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	_IniReadRegWrite($settings, "Taskbar", "LockTaskbar", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSizeMove", "REG_DWORD", "0x00000000", "0x00000001")
	_IniReadRegWrite($settings, "Taskbar", "Group", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarGlomming", "REG_DWORD", "0x00000001", "0x00000000")
	_IniReadRegWrite($settings, "Taskbar", "HideInactiveIcons", $HKUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "EnableAutoTray", "REG_DWORD", "0x00000001", "0x00000000")
EndFunc   ;==>_Taskbar

Func _TaskToolbar($toolbardir)
	; ----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.0
	; Author:Andrew Calcutt 	Date:08/09/2005
	; Script Function: Creates a toolbar in the taskbar
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	MouseClick("right", @DesktopWidth, @DesktopHeight)
	Send("{DOWN}{RIGHT}{UP}{ENTER}")
	WinWaitActive("New Toolbar")
	ControlSetText("New Toolbar", "", "Edit1", $toolbardir)
	ControlClick("New Toolbar", "", "Button2")
EndFunc   ;==>_TaskToolbar

Func _VisualSettings()
	; ----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	; AutoIt Version: 3.1.0
	; Author:Andrew Calcutt 	Date:12/24/2005
	; Script Function: Sets Visual Settings
	;-----------------------------------------------------------------------------
	;-----------------------------------------------------------------------------
	
	;LOAD SYSTEM PROPERTIES
	Run("RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3")
	;CLICK USER PROFILE SETTINGS
	While 1
		If WinExists("System Properties") Then
			ControlClick("System Properties", "Advanced", "Button2")
			ExitLoop
		EndIf
	WEnd
	
	;SET OPTIONS
	WinWaitActive("Performance Options")
	Send("!P{TAB}")
	
	If IniRead($settings, "Visual_Effects", "AWWMAM", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "FOSMIV", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "FOSTIV", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "FOMIAC", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SSUM", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SSUMP", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "STSR", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SWCWD", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SOCB", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "STB", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SEOSF", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "SSLB", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "UABIFEFT", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "UCTIF", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "UDSFILOTD", "0") = 1 Then Send("{SPACE}")
	Send("{DOWN}")
	If IniRead($settings, "Visual_Effects", "UVSOWAB", "0") = 1 Then Send("{SPACE}")
	
	ControlClick("Performance Options", "", "Button7")
	While WinExists("Performance Options")
		If ControlCommand("Performance Options", "", "Button7", "IsEnabled", "") Then
			Sleep(200)
		Else
			ControlClick("Performance Options", "", "Button5")
		EndIf
	WEnd
	While WinExists("System Properties")
		WinClose("System Properties")
	WEnd
EndFunc   ;==>_VisualSettings

Func _IniReadRegWrite($settings, $section1, $key1, $reg1, $reg2, $regtype, $regvalue1, $regvalue2)
	If IniRead($settings, $section1, $key1, "0") = 1 Then
		RegWrite($reg1, $reg2, $regtype, $regvalue1)
	Else
		RegWrite($reg1, $reg2, $regtype, $regvalue2)
	EndIf
EndFunc   ;==>_IniReadRegWrite

Func _IniReadRegWrite2($settings, $section1, $key1, $reg1, $reg2, $regtype, $regvalue1, $regvalue2, $regvalue3, $regvalue4 = "")
	If IniRead($settings, $section1, $key1, "1") = 0 Then RegWrite($reg1, $reg2, $regtype, $regvalue1)
	If IniRead($settings, $section1, $key1, "1") = 1 Then RegWrite($reg1, $reg2, $regtype, $regvalue2)
	If IniRead($settings, $section1, $key1, "1") = 2 Then RegWrite($reg1, $reg2, $regtype, $regvalue3)
	If $regvalue4 <> "" Then
		If IniRead($settings, $section1, $key1, "1") = 3 Then RegWrite($reg1, $reg2, $regtype, $regvalue4)
	EndIf
EndFunc   ;==>_IniReadRegWrite2

Func _DesktopButton($settings, $section1, $key1, $title, $button)
	If IniRead($settings, $section1, $key1, "0") = 1 Then
		If ControlCommand($title, "", $button, "IsChecked", "") = 0 Then ControlClick($title, "", $button)
	Else
		If ControlCommand($title, "", $button, "IsChecked", "") = 1 Then ControlClick($title, "", $button)
	EndIf
EndFunc   ;==>_DesktopButton

Func _RunNetSupport($fullpath_exe, $netuser, $netpass, $netdom)
	$error = 0
	;get exe filename
	$count = 2
	While 1 ;find last "\" location + 1
		$count += 1
		If StringInStr($fullpath_exe, "\", 0, $count) = 0 Then ExitLoop
	WEnd
	$count -= 1 ;subtract on to get last "\" location
	$exe = StringTrimLeft($fullpath_exe, StringInStr($fullpath_exe, "\", 0, $count));exe filename
	
	;Run Program
	If StringInStr($fullpath_exe, "\\") Then; if a netowrk location
		Send("#r");open runbox
		WinWaitActive("Run")
		ControlSetText("Run", "", "Edit1", $fullpath_exe); run exe in runbox
		ControlClick("Run", "", "Button2")
		While ProcessExists($exe) = 0
			If WinExists("Connect to") Then; if asked for credentials
				ControlSetText("Connect to", "", "Edit2", $netdom & "\" & $netuser)
				ControlSetText("Connect to", "", "Edit3", $netpass)
				ControlClick("Connect to", "", "Button2")
			EndIf
			If WinExists($fullpath_exe, "") Then
				ControlClick($fullpath_exe, "", "Button1")
				If WinExists("Run") Then ControlClick("Run", "", "Button3")
				$error = 1
				ExitLoop
			EndIf
		WEnd
		If $error <> 1 Then ProcessWaitClose($exe);wait umtill program closes
	Else
		RunWait($fullpath_exe);Run Program
		If @error = 1 Then $error = 1
	EndIf
	If $error = 1 Then
		$msgbox = MsgBox(1, "Error", $exe & " location invalid, Please choose the correct location")
		If $msgbox = 2 Then Exit
		$fullpath_exe = FileOpenDialog($exe & " Location", $workingdir, "AutoInstall (*.exe;*.bat)", 1 + 4)
		_RunNetSupport($fullpath_exe, $netuser, $netpass, $netdom)
	EndIf
EndFunc   ;==>_RunNetSupport

;<-- ######################################################### PREPSYS.EXE FUNC ######################################################### -->




Func _Set_INI_Settings()
	IniWrite($settings, "Script_Settings", "Admin_Username", GUICtrlRead($username))
	IniWrite($settings, "Script_Settings", "Admin_Password", _StringEncrypt(1, GUICtrlRead($password), "Prepsys", 2))
	IniWrite($settings, "Script_Settings", "Sysprep_Username", GUICtrlRead($username2))
	IniWrite($settings, "Script_Settings", "Sysprep_Password", _StringEncrypt(1, GUICtrlRead($password2), "Prepsys", 2))
	
	IniWrite($settings, "Background", "Specify_Image_Name", GUICtrlRead($imgname))
	IniWrite($settings, "Background", "CD_Image", GUICtrlRead($cdimgname))
	IniWrite($settings, "Background", "Specify_Image_DIR", GUICtrlRead($imgdir))
	
	IniWrite($settings, "OFFICE", "SUITES", _StringEncrypt(1, GUICtrlRead($offskey), "Prepsys", 2))
	IniWrite($settings, "OFFICE", "APPLICATIONS", _StringEncrypt(1, GUICtrlRead($offakey), "Prepsys", 2))
	
	;Write Run settings
	_IniWriteCheckbox($settings, $remuser, "Script_Settings", "Delete_Start_User", 1, "Program_Use_Only", "Deleted_Start_User", "Delete_Start_User_Step1")
	_IniWriteCheckbox($settings, $mcinstall, "Script_Settings", "Install_McAfee", 1, "Program_Use_Only", "Installed_McAfee")
	_IniWriteCheckbox($settings, $spinstall, "Script_Settings", "Install_Sophos", 1, "Program_Use_Only", "Installed_Sophos")
	_IniWriteCheckbox($settings, $vpninstall, "Script_Settings", "Install_VPN", 1, "Program_Use_Only", "Installed_VPN")
	_IniWriteCheckbox($settings, $offinstall, "Script_Settings", "Install_Office", 1, "Program_Use_Only", "Installed_Office", "Added_Office_Toolbar")
	_IniWriteCheckbox($settings, $datatel, "Script_Settings", "Install_Datatel", 1, "Program_Use_Only", "Installed_Datatel")
	_IniWriteCheckbox($settings, $deepfreeze, "Script_Settings", "Install_DeepFreeze", 1, "Program_Use_Only", "Installed_DeepFreeze")
	_IniWriteCheckbox($settings, $startmenu, "Script_Settings", "Set_Start_Menu", 1, "Program_Use_Only", "Set_Start_Menu")
	_IniWriteCheckbox($settings, $vissettings, "Script_Settings", "Set_Visual_Settings", 1, "Program_Use_Only", "Set_Visual_Settings")
	_IniWriteCheckbox($settings, $folderoptions, "Script_Settings", "Set_Folder_Options", 1, "Program_Use_Only", "Set_Folder_Options")
	_IniWriteCheckbox($settings, $copyprofile, "Script_Settings", "Copy_Profile", 1, "Program_Use_Only", "Copy_Profile_Step1", "Copy_Profile_Step2", "Copy_Profile_Step3")
	_IniWriteCheckbox($settings, $waitupdate, "Script_Settings", "Wait_Updates", 1, "Program_Use_Only", "Waited_For_Updates")
	_IniWriteCheckbox($settings, $cleansms, "Script_Settings", "Clean_SMS", 1, "Program_Use_Only", "Cleaned_SMS")
	_IniWriteCheckbox($settings, $mcguid, "Script_Settings", "Remove_McAfee_GUID", 1, "Program_Use_Only", "Removed_McAfee_GUID")
	_IniWriteCheckbox($settings, $defragment, "Script_Settings", "Defrag", 1, "Program_Use_Only", "Defraged")
	_IniWriteCheckbox($settings, $deleteini, "Script_Settings", "Delete_INI", 1)
	_IniWriteCheckbox($settings, $runsysprep, "Script_Settings", "Run_Sysprep", 1)
	;Write visual Settings
	_IniWriteCheckbox($settings, $AWWMAM, "Visual_Effects", "AWWMAM")
	_IniWriteCheckbox($settings, $FOSMIV, "Visual_Effects", "FOSMIV")
	_IniWriteCheckbox($settings, $FOSTIV, "Visual_Effects", "FOSTIV")
	_IniWriteCheckbox($settings, $SSUM, "Visual_Effects", "SSUM")
	_IniWriteCheckbox($settings, $SSUMP, "Visual_Effects", "SSUMP")
	_IniWriteCheckbox($settings, $STSR, "Visual_Effects", "STSR")
	_IniWriteCheckbox($settings, $SWCWD, "Visual_Effects", "SWCWD")
	_IniWriteCheckbox($settings, $SOCB, "Visual_Effects", "SOCB")
	_IniWriteCheckbox($settings, $STB, "Visual_Effects", "STB")
	_IniWriteCheckbox($settings, $SEOSF, "Visual_Effects", "SEOSF")
	_IniWriteCheckbox($settings, $SSLB, "Visual_Effects", "SSLB")
	_IniWriteCheckbox($settings, $UABIFEFT, "Visual_Effects", "UABIFEFT")
	_IniWriteCheckbox($settings, $UCTIF, "Visual_Effects", "UCTIF")
	_IniWriteCheckbox($settings, $UDSFILOTD, "Visual_Effects", "UDSFILOTD")
	_IniWriteCheckbox($settings, $UVSOWAB, "Visual_Effects", "UVSOWAB")
	;Write Desktop Settings
	_IniWriteCheckbox($settings, $mydocs, "Desktop_Items", "My_Documents")
	_IniWriteCheckbox($settings, $mycomp, "Desktop_Items", "My_Computer")
	_IniWriteCheckbox($settings, $mynetplaces, "Desktop_Items", "My_Network_Places")
	_IniWriteCheckbox($settings, $iexplorer, "Desktop_Items", "Internet_Explorer")
	_IniWriteCheckbox($settings, $cleandesk, "Desktop_Items", "Enable_Desktop_Cleanup")
	;Write Start Menu Settings
	_IniWriteCombo($settings, $ShowControlPanel, "StartMenu", "ShowControlPanel")
	_IniWriteCombo($settings, $ShowMyComputer, "StartMenu", "ShowMyComputer")
	_IniWriteCombo($settings, $ShowMyDocs, "StartMenu", "ShowMyDocs")
	_IniWriteCombo($settings, $ShowMyMusic, "StartMenu", "ShowMyMusic")
	_IniWriteCombo($settings, $ShowMyPics, "StartMenu", "ShowMyPics")
	_IniWriteCombo($settings, $ShowNetConn, "StartMenu", "ShowNetConn")
	_IniWriteCombo($settings, $ShowAdminTools, "StartMenu", "ShowAdminTools")
	_IniWriteCheckbox($settings, $ShowSetProgramAccessAndDefaults, "StartMenu", "ShowSetProgramAccessAndDefaults")
	_IniWriteCheckbox($settings, $StartMenuFavorites, "StartMenu", "StartMenuFavorites")
	_IniWriteCheckbox($settings, $EnableDragDrop, "StartMenu", "EnableDragDrop")
	_IniWriteCheckbox($settings, $ScrollPrograms2, "StartMenu", "ScrollPrograms")
	_IniWriteCheckbox($settings, $ShowHelp, "StartMenu", "ShowHelp")
	_IniWriteCheckbox($settings, $ShowPrinters, "StartMenu", "ShowPrinters")
	_IniWriteCheckbox($settings, $ShowRun, "StartMenu", "ShowRun")
	_IniWriteCheckbox($settings, $ShowSearch, "StartMenu", "ShowSearch")
	_IniWriteCheckbox($settings, $Classic_Menu, "StartMenu", "Classic_Menu")
	;write Classic  Menu Settings
	_IniWriteCheckbox($settings, $DisplayAdminTools, "Classic_Menu_Options", "DisplayAdminTools")
	_IniWriteCheckbox($settings, $DisplayFavories, "Classic_Menu_Options", "DisplayFavories")
	_IniWriteCheckbox($settings, $DisplayLogOff, "Classic_Menu_Options", "DisplayLogOff")
	_IniWriteCheckbox($settings, $DisplayRun, "Classic_Menu_Options", "DisplayRun")
	_IniWriteCheckbox($settings, $EnableDRAGandDROP, "Classic_Menu_Options", "EnableDRAGandDROP")
	_IniWriteCheckbox($settings, $ExpandControlPanel, "Classic_Menu_Options", "ExpandControlPanel")
	_IniWriteCheckbox($settings, $ExpandMyDocuments, "Classic_Menu_Options", "ExpandMyDocuments")
	_IniWriteCheckbox($settings, $ExpandMyPictures, "Classic_Menu_Options", "ExpandMyPictures")
	_IniWriteCheckbox($settings, $ExpandNetworkConnections, "Classic_Menu_Options", "ExpandNetworkConnections")
	_IniWriteCheckbox($settings, $ExpandPrinters, "Classic_Menu_Options", "ExpandPrinters")
	_IniWriteCheckbox($settings, $ScrollPrograms, "Classic_Menu_Options", "ScrollPrograms")
	_IniWriteCheckbox($settings, $UsePersonalizedMenus, "Classic_Menu_Options", "UsePersonalizedMenus")
	;Write Office settings
	_IniWriteCheckbox($settings, $offtool, "OFFICE", "Add_Office_Toolbar")
	;Write Folder settings
	_IniWriteCheckbox($settings, $SearchNetPrinters, "Folder_Options", "SearchNetPrinters")
	_IniWriteCheckbox($settings, $DisplayFileSizeInFolderTips, "Folder_Options", "DisplayFileSizeInFolderTips")
	_IniWriteCheckbox($settings, $SimpleViewInFolderListView, "Folder_Options", "SimpleViewInFolderListView")
	_IniWriteCheckbox($settings, $DisplaySystemFolderContents, "Folder_Options", "DisplaySystemFolderContents")
	_IniWriteCheckbox($settings, $FullPathAddress, "Folder_Options", "FullPathAddress")
	_IniWriteCheckbox($settings, $FullPathTitle, "Folder_Options", "FullPathTitle")
	_IniWriteCheckbox($settings, $CacheThumbnails, "Folder_Options", "CacheThumbnails")
	_IniWriteCheckbox($settings, $ShowHiddenFiles, "Folder_Options", "ShowHiddenFiles")
	_IniWriteCheckbox($settings, $ShowFileExtensions, "Folder_Options", "ShowFileExtensions")
	_IniWriteCheckbox($settings, $ShowHiddenSysFiles, "Folder_Options", "ShowHiddenSysFiles")
	_IniWriteCheckbox($settings, $LaunchWindowsInSeperateProcess, "Folder_Options", "LaunchWindowsInSeperateProcess")
	_IniWriteCheckbox($settings, $RememberFolderSettings, "Folder_Options", "RememberFolderSettings")
	_IniWriteCheckbox($settings, $RestoreWindowsAtLogon, "Folder_Options", "RestoreWindowsAtLogon")
	_IniWriteCheckbox($settings, $ControlPanelInMyComputer, "Folder_Options", "ControlPanelInMyComputer")
	_IniWriteCheckbox($settings, $ShowCompressedFilesInColor, "Folder_Options", "ShowCompressedFilesInColor")
	_IniWriteCheckbox($settings, $ShowDesktopFolderInfoPopop, "Folder_Options", "ShowDesktopFolderInfoPopop")
	_IniWriteCheckbox($settings, $UseSimpleFileSharing, "Folder_Options", "UseSimpleFileSharing")
	
	_ExeLocationWrite($mcafee_exe, $mcafee_exe2, $settings, "Program_Use_Only", "mcafee_exe")
	_ExeLocationWrite($mcafee_patch_exe, $mcafee_patch_exe2, $settings, "Program_Use_Only", "mcafee_patch_exe")
	_ExeLocationWrite($sophos_exe, $sophos_exe2, $settings, "Program_Use_Only", "sophos_exe")
	_ExeLocationWrite($vpn_exe, $vpn_exe2, $settings, "Program_Use_Only", "vpn_exe")
	_ExeLocationWrite($office_exe, $office_exe2, $settings, "Program_Use_Only", "office_exe")
	_ExeLocationWrite($datatel_exe, $datatel_exe2, $settings, "Program_Use_Only", "datatel_exe")
	_ExeLocationWrite($deepfreeze_exe, $deepfreeze_exe2, $settings, "Program_Use_Only", "deepfreeze_exe")
	_ExeLocationWrite($cleansms_exe, $cleansms_exe2, $settings, "Program_Use_Only", "cleansms_exe")
	
	;If network drive used(idendtified by "\\") and set to run, Set flag for network logon prompt
	If StringInStr(GUICtrlRead($mcafee_exe2), "\\") And GUICtrlRead($mcinstall) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($mcafee_patch_exe2), "\\") And GUICtrlRead($mcinstall) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($sophos_exe2), "\\") And GUICtrlRead($spinstall) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($vpn_exe2), "\\") And GUICtrlRead($vpninstall) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($office_exe2), "\\") And GUICtrlRead($offinstall) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($datatel_exe2), "\\") And GUICtrlRead($datatel) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($deepfreeze_exe2), "\\") And GUICtrlRead($deepfreeze) = 1 Then $requestnetwork = 1
	If StringInStr(GUICtrlRead($cleansms_exe2), "\\") And GUICtrlRead($cleansms) = 1 Then $requestnetwork = 1
	
	_NetworkLogin()
	
	IniWrite($settings, "Program_Use_Only", "Progress_Ref", $progressref)
	IniWrite($settings, "Program_Use_Only", "Progress_Ref2", "0")

	IniWrite($settings, "Script_Settings", "Working_Dir", "")
EndFunc   ;==>_Set_INI_Settings

Func _Sophos_State()
	If GUICtrlRead($mcinstall) = 1 Then
		GUICtrlSetState($spinstall, $GUI_UNCHECKED)
		GUICtrlSetState($spinstall, $GUI_DISABLE)
	Else
		GUICtrlSetState($spinstall, $GUI_ENABLE)
	EndIf
EndFunc   ;==>_Sophos_State

Func _McAfee_State()
	If GUICtrlRead($spinstall) = 1 Then
		GUICtrlSetState($mcinstall, $GUI_UNCHECKED)
		GUICtrlSetState($mcinstall, $GUI_DISABLE)
	Else
		GUICtrlSetState($mcinstall, $GUI_ENABLE)
	EndIf
EndFunc   ;==>_McAfee_State

Func _Office_State()
	If GUICtrlRead($offinstall) = 1 Then
		_State($GUI_ENABLE, $offskey, $offakey, $offtool, $offlabel1, $offlabel2, "", "", "", "", "")
	Else
		_State($GUI_DISABLE, $offskey, $offakey, $offtool, $offlabel1, $offlabel2, "", "", "", "", "")
	EndIf
EndFunc   ;==>_Office_State

Func _Sysprep_User_State()
	If GUICtrlRead($copyprofile) = 1 Then
		_State($GUI_ENABLE, $username2, $password2, $cplabel1, $cplabel2, "", "", "", "", "", "")
	Else
		_State($GUI_DISABLE, $username2, $password2, $cplabel1, $cplabel2, "", "", "", "", "", "")
	EndIf
EndFunc   ;==>_Sysprep_User_State

Func _Folder_Options_State()
	If GUICtrlRead($folderoptions) = 1 Then
		_State($GUI_ENABLE, $SearchNetPrinters, $DisplayFileSizeInFolderTips, $SimpleViewInFolderListView, $DisplaySystemFolderContents, $FullPathAddress, $FullPathTitle, $CacheThumbnails, $ShowHiddenFiles, $ShowFileExtensions, $ShowHiddenSysFiles)
		_State($GUI_ENABLE, $LaunchWindowsInSeperateProcess, $RememberFolderSettings, $RestoreWindowsAtLogon, $ControlPanelInMyComputer, $ShowCompressedFilesInColor, $ShowDesktopFolderInfoPopop, $UseSimpleFileSharing, "", "", "")
	Else
		_State($GUI_DISABLE, $SearchNetPrinters, $DisplayFileSizeInFolderTips, $SimpleViewInFolderListView, $DisplaySystemFolderContents, $FullPathAddress, $FullPathTitle, $CacheThumbnails, $ShowHiddenFiles, $ShowFileExtensions, $ShowHiddenSysFiles)
		_State($GUI_DISABLE, $LaunchWindowsInSeperateProcess, $RememberFolderSettings, $RestoreWindowsAtLogon, $ControlPanelInMyComputer, $ShowCompressedFilesInColor, $ShowDesktopFolderInfoPopop, $UseSimpleFileSharing, "", "", "")
	EndIf
EndFunc   ;==>_Folder_Options_State

Func _VisSettings_State()
	If GUICtrlRead($vissettings) = 1 Then
		_State($GUI_ENABLE, $AWWMAM, $FOSMIV, $FOSTIV, $SSUM, $SSUMP, $STSR, $SWCWD, $SOCB, $STB, $SEOSF)
		_State($GUI_ENABLE, $SSLB, $UABIFEFT, $UCTIF, $UDSFILOTD, $UVSOWAB, $mydocs, $mycomp, $mynetplaces, $iexplorer, $cleandesk)
		_State($GUI_ENABLE, $imgname, $cdimgname, $imgdir, $imglab1, $imglab2, $imglab3, $imglab4, "", "", "")
	Else
		_State($GUI_DISABLE, $AWWMAM, $FOSMIV, $FOSTIV, $SSUM, $SSUMP, $STSR, $SWCWD, $SOCB, $STB, $SEOSF)
		_State($GUI_DISABLE, $SSLB, $UABIFEFT, $UCTIF, $UDSFILOTD, $UVSOWAB, $mydocs, $mycomp, $mynetplaces, $iexplorer, $cleandesk)
		_State($GUI_DISABLE, $imgname, $cdimgname, $imgdir, $imglab1, $imglab2, $imglab3, $imglab4, "", "", "")
	EndIf
EndFunc   ;==>_VisSettings_State

Func _StartMenuState()
	If GUICtrlRead($startmenu) = 1 Then
		_State($GUI_ENABLE, $DisplayAdminTools, $DisplayFavories, $DisplayLogOff, $DisplayRun, $EnableDRAGandDROP, $ExpandControlPanel, $ExpandMyDocuments, $ExpandMyPictures, $ExpandNetworkConnections, $ExpandPrinters)
		_State($GUI_ENABLE, $ScrollPrograms, $UsePersonalizedMenus, $snclabel, $satlabel, $Classic_Menu, "", "", "", "", "")
		_State($GUI_ENABLE, $ShowControlPanel, $ShowMyComputer, $ShowMyDocs, $ShowMyMusic, $ShowMyPics, $ShowNetConn, $ShowAdminTools, $EnableDragDrop, $ScrollPrograms2, $ShowHelp)
		_State($GUI_ENABLE, $ShowPrinters, $ShowRun, $ShowSearch, $ShowSetProgramAccessAndDefaults, $StartMenuFavorites, $scplabel, $smclabel, $smdlabel, $smmlabel, $smplabel)
	Else
		_State($GUI_DISABLE, $DisplayAdminTools, $DisplayFavories, $DisplayLogOff, $DisplayRun, $EnableDRAGandDROP, $ExpandControlPanel, $ExpandMyDocuments, $ExpandMyPictures, $ExpandNetworkConnections, $ExpandPrinters)
		_State($GUI_DISABLE, $ScrollPrograms, $UsePersonalizedMenus, $snclabel, $satlabel, $Classic_Menu, "", "", "", "", "")
		_State($GUI_DISABLE, $ShowControlPanel, $ShowMyComputer, $ShowMyDocs, $ShowMyMusic, $ShowMyPics, $ShowNetConn, $ShowAdminTools, $EnableDragDrop, $ScrollPrograms2, $ShowHelp)
		_State($GUI_DISABLE, $ShowPrinters, $ShowRun, $ShowSearch, $ShowSetProgramAccessAndDefaults, $StartMenuFavorites, $scplabel, $smclabel, $smdlabel, $smmlabel, $smplabel)
	EndIf
EndFunc   ;==>_StartMenuState

Func _StartMenuSwitch()
	If GUICtrlRead($Classic_Menu) = 1 Then
		_State($GUI_ENABLE, $DisplayAdminTools, $DisplayFavories, $DisplayLogOff, $DisplayRun, $EnableDRAGandDROP, $ExpandControlPanel, $ExpandMyDocuments, $ExpandMyPictures, $ExpandNetworkConnections, $ExpandPrinters)
		_State($GUI_ENABLE, $ScrollPrograms, $UsePersonalizedMenus, "", "", "", "", "", "", "", "")
		_State($GUI_DISABLE, $ShowControlPanel, $ShowMyComputer, $ShowMyDocs, $ShowMyMusic, $ShowMyPics, $ShowNetConn, $ShowAdminTools, $EnableDragDrop, $ScrollPrograms2, $ShowHelp)
		_State($GUI_DISABLE, $ShowPrinters, $ShowRun, $ShowSearch, $ShowSetProgramAccessAndDefaults, $StartMenuFavorites, $scplabel, $smclabel, $smdlabel, $smmlabel, $smplabel)
		_State($GUI_DISABLE, $snclabel, $satlabel, "", "", "", "", "", "", "", "")
	Else
		_State($GUI_DISABLE, $DisplayAdminTools, $DisplayFavories, $DisplayLogOff, $DisplayRun, $EnableDRAGandDROP, $ExpandControlPanel, $ExpandMyDocuments, $ExpandMyPictures, $ExpandNetworkConnections, $ExpandPrinters)
		_State($GUI_DISABLE, $ScrollPrograms, $UsePersonalizedMenus, "", "", "", "", "", "", "", "")
		_State($GUI_ENABLE, $ShowControlPanel, $ShowMyComputer, $ShowMyDocs, $ShowMyMusic, $ShowMyPics, $ShowNetConn, $ShowAdminTools, $EnableDragDrop, $ScrollPrograms2, $ShowHelp)
		_State($GUI_ENABLE, $ShowPrinters, $ShowRun, $ShowSearch, $ShowSetProgramAccessAndDefaults, $StartMenuFavorites, $scplabel, $smclabel, $smdlabel, $smmlabel, $smplabel)
		_State($GUI_ENABLE, $snclabel, $satlabel, "", "", "", "", "", "", "", "")
	EndIf
EndFunc   ;==>_StartMenuSwitch


Func _IniReadCheckbox_Ran($settings, ByRef $id, $name, $section1, $key1, $section2, $key2, $CR, $CT, $CW, $CH, $RR)
	$id = GUICtrlCreateCheckbox($name, $CR, $CT, $CW, $CH)
	If IniRead($settings, $section1, $key1, "") = 1 Then
		If IniRead($settings, $section2, $key2, "") = 0 Then GUICtrlSetState($id, $GUI_CHECKED)
	EndIf
	If IniRead($settings, $section2, $key2, "") = 1 Then GUICtrlCreatePic($workingdir & "PrepSys\ran.bmp", $RR, $CT, $CH, $CH)
EndFunc   ;==>_IniReadCheckbox_Ran

Func _IniReadCheckbox($settings, ByRef $id, $name, $section1, $key1, $CR, $CT, $CW, $CH)
	$id = GUICtrlCreateCheckbox($name, $CR, $CT, $CW, $CH)
	If IniRead($settings, $section1, $key1, "") = 1 Then
		If IniRead($settings, $section1, $key1, "") = 1 Then GUICtrlSetState($id, $GUI_CHECKED)
	EndIf
EndFunc   ;==>_IniReadCheckbox

Func _IniWriteCheckbox($settings, ByRef $id, $section1, $key1, $progress = "", $section2 = "", $key2 = "", $key3 = "", $key4 = "")
	If GUICtrlRead($id) = 1 Then
		If $progress = 1 Then $progressref += 1
		IniWrite($settings, $section1, $key1, "1")
		If $key2 <> "" Then IniWrite($settings, $section2, $key2, "0")
		If $key3 <> "" Then IniWrite($settings, $section2, $key3, "0")
		If $key4 <> "" Then IniWrite($settings, $section2, $key4, "0")
	Else
		IniWrite($settings, $section1, $key1, "0")
		If $key2 <> "" Then IniWrite($settings, $section2, $key2, "0")
		If $key3 <> "" Then IniWrite($settings, $section2, $key3, "0")
		If $key4 <> "" Then IniWrite($settings, $section2, $key4, "0")
	EndIf
EndFunc   ;==>_IniWriteCheckbox

Func _LabeledCombo($settings, ByRef $id, ByRef $id2, $label, $section1, $key1, $item0, $item1, $item2, $R, $T, $W, $H, $LR, $LT, $LW, $LH)
	$id2 = GUICtrlCreateLabel($label, $LR, $T, $W, $H)
	$state = IniRead($settings, $section1, $key1, "")
	Select
		Case $state = 0
			$id = GUICtrlCreateCombo($item0, $R, $T, $W, $H)
			GUICtrlSetData(-1, $item1 & "|" & $item2)
		Case $state = 1
			$id = GUICtrlCreateCombo($item1, $R, $T, $W, $H)
			GUICtrlSetData(-1, $item2 & "|" & $item0)
		Case $state = 2
			$id = GUICtrlCreateCombo($item2, $R, $T, $W, $H)
			GUICtrlSetData(-1, $item1 & "|" & $item0)
	EndSelect
EndFunc   ;==>_LabeledCombo

Func _IniWriteCombo($settings, ByRef $id, $section1, $key1)
	Select
		Case GUICtrlRead($id) = "Disabled"
			IniWrite($settings, $section1, $key1, "0")
		Case GUICtrlRead($id) = "Link" Or GUICtrlRead($id) = "Net Connections" Or GUICtrlRead($id) = "Programs"
			IniWrite($settings, $section1, $key1, "1")
		Case GUICtrlRead($id) = "Menu" Or GUICtrlRead($id) = "Connect to" Or GUICtrlRead($id) = "Start menu + progs"
			IniWrite($settings, $section1, $key1, "2")
	EndSelect
EndFunc   ;==>_IniWriteCombo

Func _FileBrowse($default, ByRef $input, ByRef $browse, $R, $T, $W, $H, $BR, $BW)
	$input = GUICtrlCreateInput($default, $R, $T, $W, $H)
	$browse = GUICtrlCreateButton("...", $BR, $T, $BW, $H)
EndFunc   ;==>_FileBrowse

Func _FileBrowseSet(ByRef $exe, $label)
	$opendialog = FileOpenDialog($label, $workingdir, "AutoInstall (*.exe;*.bat)", 1 + 4)
	If @error <> 1 Then GUICtrlSetData($exe, $opendialog)
EndFunc   ;==>_FileBrowseSet

Func _State(Const $state, Const $1, Const $2, Const $3, Const $4, Const $5, Const $6, Const $7, Const $8, Const $9, Const $10)
	If $1 <> "" Then GUICtrlSetState($1, $state)
	If $2 <> "" Then GUICtrlSetState($2, $state)
	If $3 <> "" Then GUICtrlSetState($3, $state)
	If $4 <> "" Then GUICtrlSetState($4, $state)
	If $5 <> "" Then GUICtrlSetState($5, $state)
	If $6 <> "" Then GUICtrlSetState($6, $state)
	If $7 <> "" Then GUICtrlSetState($7, $state)
	If $8 <> "" Then GUICtrlSetState($8, $state)
	If $9 <> "" Then GUICtrlSetState($9, $state)
	If $10 <> "" Then GUICtrlSetState($10, $state)
EndFunc   ;==>_State

Func _ExeLocationWrite(Const $orig, Const $file, Const $settings, $section1, $key1)
	If $orig <> GUICtrlRead($file) Then
		IniWrite($settings, $section1, $key1, GUICtrlRead($file))
	EndIf
EndFunc   ;==>_ExeLocationWrite

Func _NetworkLogin()
	GUIDelete()
	If $requestnetwork = 1 Then
		IniWrite($settings, "Program_Use_Only", "NetLogon", "1")
	Else
		IniWrite($settings, "Program_Use_Only", "NetLogon", "0")
	EndIf
	
	If $requestnetwork = 1 And $shownetprompt = 1 Then
		
		GUICreate("Network Logon", 186, 140)
		GUICtrlCreateLabel("Username", 0, 10, 50, 20)
		$netuser = GUICtrlCreateInput($netuser, 50, 10, 120, 20)
		GUICtrlCreateLabel("Password", 0, 40, 50, 20)
		$netpass = GUICtrlCreateInput($netpass, 50, 40, 120, 20, $ES_PASSWORD)
		GUICtrlCreateLabel("Domain", 0, 70, 40, 20)
		$netdom = GUICtrlCreateInput($netdom, 50, 70, 120, 20)
		$skipnetlogon = GUICtrlCreateCheckbox("Skip logon prompt on next load", 5, 90, 180, 20)
		$continue = GUICtrlCreateButton("Continue", 20, 115, 70, 20)
		$exit = GUICtrlCreateButton("Exit", 100, 115, 70, 20)
		
		GUISetState()
		While 1
			$msg = GUIGetMsg()
			Select
				Case $msg = $GUI_EVENT_CLOSE Or $msg = $exit
					Exit
				Case $msg = $continue
					IniWrite($settings, "Program_Use_Only", "NetAdmin", GUICtrlRead($netuser))
					IniWrite($settings, "Program_Use_Only", "NetPass", _StringEncrypt(1, GUICtrlRead($netpass), "Prepsys", 2))
					IniWrite($settings, "Program_Use_Only", "NetDom", GUICtrlRead($netdom))
					
					If GUICtrlRead($skipnetlogon) = 1 Then
						IniWrite($settings, "Program_Use_Only", "ShowNetLoginPrompt", "0")
					Else
						IniWrite($settings, "Program_Use_Only", "ShowNetLoginPrompt", "1")
					EndIf
					
					ExitLoop
				Case Else
					;;;
			EndSelect
		WEnd
	EndIf
EndFunc   ;==>_NetworkLogin