Good morning. I am new to all this, so please be gentle. If you could in particular check out my Copy_KixForms function, I'd like to ensure that I've got that looking good... Any other comments suggestions are welcome.
Thanks,
Chris
Code:
;*******************************************************************************
;** Script: kixtart.kix
;** Created: 3-7-2005
;**
;** This is the specific Kix script. It will be generally called from
;** login script via a Group Policy object.
;**
;** Please remember to comment and date any modifcations that you make.
;**
;** Please keep the Skip Logon Script portion of the script
;** at the beginning, as it checks to see if you are logging
;** on to a Server or part of the Domain Admins, IT Dept
;** groups.
;**
;*******************************************************************************
;*******************************************************************************
; C H A N G E H I S T O R Y
;*******************************************************************************
; Date ID Description of change
;*******************************************************************************
; 3-7-05 CVC Created
; 3-8-05 CVC Added Copy_Files Function (ScreenSaver)
;
;*******************************************************************************
; C H A N G E H I S T O R Y
;*******************************************************************************
;Break OFF
;*******************************************************************************
;** Constant Variables
;*******************************************************************************
$RegistryCheck = "HKLM\Software\Company Name"
$SysFolder = %WinDir% + '\system32'
$LocalDC = "\\domain-dc01"
;*******************************************************************************
;** Skip logon script if connected to VPN
;*******************************************************************************
;** Builds the IP address in a usable format.
$IP1 = Ltrim(SubStr(@IPADDRESS0, 1, 3))
$IP2 = Ltrim(SubStr(@IPADDRESS0, 5, 3))
$IP3 = Ltrim(SubStr(@IPADDRESS0, 9, 3))
$IP4 = Ltrim(SubStr(@IPADDRESS0, 13, 3))
;** The trimmed IP address is rebuild of the four octets, again seperated by dots...
$CurrentIP=$IP1 + "." + $IP2 + "." + $IP3 + "." + $IP4
If InStr($CurrentIP, "192.168")
Exit
EndIf
;*******************************************************************************
;** Check who and where you are logging on to
;*******************************************************************************
If InStr(@PRODUCTTYPE,"Server") Or InStr(@PRODUCTTYPE,"Domain Controller")
$msg = MessageBox ("Login script has been aborted..." + @CRLF + @CRLF + "Logging on to a server.","Notice",48)
Exit
Else
If InGroup("IT DEPT")
Copy_KixForms
$FuncToExecute=Split("Set_SUS_Server,TrackIT,Add_Users,Copy_Files,End_Login_Script",",")
Else
;** If you want something to run, it must be put in this section. Create a
;** function, and put it in the function to execute below.
;**
;** Copy_KixForms must be the first function called, as it checks to see if
;** required files are installed and registered.
;**
Copy_KixForms
$FuncToExecute=Split("Set_SUS_Server,Set_IE_Limits,TrackIT,Add_Users,Copy_Files,End_Login_Script",",")
EndIf
;*******************************************************************************
;** Start Form System
;*******************************************************************************
$System = CreateObject("Kixtart.System")
$Root = $System.Form()
;*******************************************************************************
;** Main Form
;*******************************************************************************
$frmMain = $System.Form($Root)
$frmMain.ShowInTaskBar = "False"
$frmMain.BorderStyle = 1
$frmMain.SysMenu = 0
$frmMain.ControlBox = 0
$frmMain.Size = 320,280
$frmMain.Text = "Welcome to the @DOMAIN Domain"
$frmMain.Center
$frmMain.TopMost = 1
;*******************************************************************************
;** User Information GroupBox
;*******************************************************************************
$fraUser = $frmMain.GroupBox
$fraUser.Size = 300,170
$fraUser.Center
$fraUser.Top = 0
$FraUser.Text = "User Information:"
$lblFName = $fraUser.Label("Full Name:",5,22,75,20)
$lblFName.Alignment = 1
$txtFName = $fraUser.TextBox(@FULLNAME,85,20,205,20)
$txtFName.ReadOnly = 1
$lblUserID = $fraUser.Label("Username:",5,42,75,20)
$lblUserID.Alignment = 1
$txtUserID = $fraUser.TextBox(@USERID,85,40,205,20)
$txtUserID.ReadOnly = 1
$lblLServer = $fraUser.Label("Logon Server:",5,62,75,20)
$lblLServer.Alignment = 1
$txtLServer = $fraUser.TextBox(@LSERVER,85,60,205,20)
$txtLServer.ReadOnly = 1
$lblLDom = $fraUser.Label("Logon Domain:",5,82,75,20)
$lblLDom.Alignment = 1
$txtLDom = $fraUser.TextBox(@DOMAIN,85,80,205,20)
$txtLDom.ReadOnly = 1
$lblComp = $fraUser.Label("Computer:",5,102,75,20)
$lblComp.Alignment = 1
$txtComp = $fraUser.TextBox(@HOSTNAME,85,100,205,20)
$txtComp.ReadOnly = 1
$lblIP = $fraUser.Label("IP Address:",5,122,75,20)
$lblIP.Alignment = 1
$txtIP = $fraUser.TextBox($CurrentIP,85,120,205,20)
$txtIP.ReadOnly = 1
$lblMAC = $fraUser.Label("MAC Address:",5,142,75,20)
$lblMAC.Alignment = 1
$txtMAC = $fraUser.TextBox(@ADDRESS,85,140,205,20)
$txtMAC.ReadOnly = 1
;*******************************************************************************
;** Logon Process GroupBox and ProgressBar
;*******************************************************************************
$fraStatus = $frmMain.GroupBox
$fraStatus.Size = 300,70
$fraStatus.Center
$fraStatus.Top = $fraUser.Bottom + 5
$fraStatus.Text = "Logon Process:"
$lblStatus = $fraStatus.Label("Processing logon script...",10,20,260,20)
$prgStatus = $fraStatus.ProgressBar
$prgStatus.Size = 280,20
$prgStatus.Center
$prgStatus.Top = $lblStatus.Bottom
;*******************************************************************************
;** Function Status and ProgressBar Form
;*******************************************************************************
$frmFuncStatus = $System.Form($Root)
$frmFuncStatus.ShowInTaskBar = "False"
$frmFuncStatus.BorderStyle = 1
$frmFuncStatus.SysMenu = 0 ; Disable the sysmenu. Prevents users from closing forms
$frmFuncStatus.ControlBox = 0
$frmFuncStatus.Size = 320,80
$frmFuncStatus.Text = "Processing function..."
$frmFuncStatus.Center
$frmFuncStatus.Top = $frmFuncStatus.Top + ($frmMain.Height/2)+50
$lblFuncStatus = $frmFuncStatus.Label("Processing function...")
$lblFuncStatus.Size = 300,20
$lblFuncStatus.Center
$lblFuncStatus.Top = 5
$prgFuncStatus = $frmFuncStatus.ProgressBar
$prgFuncStatus.Size = 300,20
$prgFuncStatus.Center
$prgFuncStatus.Top = $lblFuncStatus.Bottom
;*******************************************************************************
;** End Form System
;*******************************************************************************
$frmMain.Show
$prgStatus.Max = Ubound($FuncToExecute)+1
For Each $sFunction in $FuncToExecute
$prgStatus.Value = $prgStatus.Value+1
$nul=Execute($sFunction)
Sleep 1
Next
Exit
;*******************************************************************************
;** Start of Functions
;*******************************************************************************
Function Copy_KixForms()
$NetKixForms = $LocalDC + '\netlogon\kix\kixforms.dll'
$LocalKixForms = $SysFolder + '\kixforms.dll'
If Not Exist ($LocalKixForms)
Copy $NetKixForms $LocalKixForms /h /r
Shell 'regsvr32 /s ' + $LocalKixForms
EndIf
$NetVersion = GetFileVersion ($NetKixForms)
$LocalVersion = GetFileVersion ($LocalKixForms)
If $LocalVersion <> $NetVersion
Shell 'regsvr32 /u /s ' + $LocalKixForms
Copy $NetKixForms $LocalKixForms /h /r
Shell 'regsvr32 /s ' + $LocalKixForms
EndIf
EndFunction
Function LOGINFO($FILE,$STRING)
;Used to make login script log files.
;Example LogInfo("\\server\log$\VERSION.LOG","@DATE @TIME,@WKSTA,@USERID")
$junk = RedirectOutput($file)
$string ?
$junk = RedirectOutput("")
EndFunction
Function Set_SUS_Server()
$lblStatus.Text = "Checking SUS settings..."
Sleep 1
;** Set registry keys for SUS
$WU = "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$AU = "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
If Not KeyExist($WU)
AddKey($WU)
$rc = WriteValue($WU, "WUServer", "http://sus.com", "REG_SZ")
$rc = WriteValue($WU, "WUStatusServer", "http://sus.com", "REG_SZ")
EndIf
If Not KeyExist($AU)
AddKey($AU)
$rc = WriteValue($AU, "RescheduleWaitTime", "15", "REG_DWORD")
$rc = WriteValue($AU, "NoAutoRebootWithLoggedOnUser", "1", "REG_DWORD")
$rc = WriteValue($AU, "NoAutoUpdate", "0", "REG_DWORD")
$rc = WriteValue($AU, "AUOptions", "4", "REG_DWORD")
$rc = WriteValue($AU, "ScheduledInstallDay", "0", "REG_DWORD")
$rc = WriteValue($AU, "ScheduledInstallTime", "3", "REG_DWORD")
$rc = WriteValue($AU, "UseWUServer", "1", "REG_DWORD")
EndIf
$lblStatus.Text = "SUS settings up-to-date..."
EndFunction
Function Set_IE_Limits()
$lblStatus.Text = "Checking Internet Explorer settings..."
Sleep 1
$lblStatus.Text = "Please wait..."
$frmFuncStatus.Text = "Internet Explorer"
$prgFuncStatus.Max = 10
$prgFuncStatus.Value = ""
$lblFuncStatus.Text = "Setting Internet Exploer defaults..."
$frmFuncStatus.Show
For $lX = 1 to 3 $prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 0.5 Next
$lblFuncStatus.Text = "Default Homepage..."
;** Set default homepage
;** https://www.intranet.com
$DefaultStartPage="HKCU\Software\Microsoft\Internet Explorer\Main"
$rc = WriteValue($DefaultStartPage, "Start Page", "https://www.intranet.com", "REG_SZ")
For $lX = 1 to 3 $prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 0.5 Next
$lblFuncStatus.Text = "Temporary Internet Files..."
;** Clearing of Temporary Internet Files on Exit
;** 0 = Yes
;** 1 = No
$PersistentCache = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache"
$rc = WriteValue($PersistentCache, "Persistent", "1", "REG_DWORD")
;** Sets amount the Temporary Internet Files can get to
;** Amount multiplied by 1024
;** 80 * 1024 = 81920
;** 100 * 1024 = 102400
$CacheLimit = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content"
$rc = WriteValue($CacheLimit, "CacheLimit", "81920", "REG_DWORD")
;** Disable the ability to change Temporary Internet Files size
;** 0 = Off
;** 1 = On
$Internet_Cache_On_Off = "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel"
$rc = WriteValue($Internet_Cache_On_Off, "Cache", "1", "REG_DWORD")
For $lX = 1 to 3 $prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 0.5 Next
$lblFuncStatus.Text = "Internet Explorer History..."
$prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 1
Sleep 0.5
$frmFuncStatus.Hide
;** Sets number of days to keep history
;** 30 Days
$DaysToKeep = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Url History"
$rc = WriteValue($DaysToKeep, "DaysToKeep", "30", "REG_DWORD")
;** Disable the ability to change/clear History
;** 0 = Off
;** 1 = On
$Clear_History_On_Off = "HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel"
$rc = WriteValue($Clear_History_On_Off, "History", "1", "REG_DWORD")
EndFunction
Function TrackIT()
$lblStatus.Text = "Checking Inventory Date..."
Sleep 1
$lblStatus.Text = "Please wait, running computer inventory..."
$frmFuncStatus.Text = "PC Inventory"
$prgFuncStatus.Max = 10
$prgFuncStatus.Value = ""
$lblFuncStatus.Text = "Computer Hardware..."
$frmFuncStatus.Show
If InStr(%OS%,"Windows_NT")
Shell "start /low \\server\audit32.exe"
Else
Shell "start \\server\audit32.exe"
EndIf
For $lX = 1 to 6 $prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 0.5 Next
$lblFuncStatus.Text = "Computer Software..."
For $lX = 1 to 3 $prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 0.5 Next
$lblFuncStatus.Text = "Saving Inventory to Database..."
;** Calling the Create_Log function to output
Create_Log
$prgFuncStatus.Value = $prgFuncStatus.Value + 1 Sleep 1
$frmFuncStatus.Hide
EndFunction
Function Add_Users()
$lblStatus.Text = "Adding Groups..."
Sleep 1
If Not ReadValue($RegistryCheck, "AdminGroups")
Run 'net localgroup administrators "domain\domain admins" /add'
Run 'net localgroup administrators domain\domain-localadmin /add'
$rc = WriteValue($RegistryCheck, "AdminGroups", "1", "REG_DWORD")
EndIf
$lblStatus.Text = "Groups up-to-date..."
EndFunction
Function Copy_Files()
$lblStatus.Text = "Copying Files..."
$NetScreenSaver = $LocalDC + '\netlogon\screensaver.scr'
$LocalScreenSaver = $SysFolder + '\screensaver.scr'
Sleep 1
If Not Exist ($LocalScreenSaver)
Copy $NetScreenSaver $LocalScreenSaver /h /r
EndIf
$lblStatus.Text = "Finished Copying Files..."
EndFunction
Function Create_Log()
;** Checks to see if the MAC Address has already been recorded, if it has
;** it will bypass this step.
If Not ReadValue($RegistryCheck, "MAC Address")
LogInfo("\\server\MAC-Address.csv","@DATE,@WKSTA,$CurrentIP,@Address")
$rc = WriteValue($RegistryCheck, "MAC Address", "1", "REG_DWORD")
EndIf
If Not ReadValue($RegistryCheck, "BarFCDataEntry")
$BarFC = $SysFolder + '\BarFCMain7.dll'
If Exist ($BarFC)
LogInfo("\\server\BarFC.csv","@DATE,@WKSTA,$CurrentIP,@Address")
$rc = WriteValue($RegistryCheck, "BarFCDataEntry", "1", "REG_DWORD")
EndIf
EndIf
EndFunction
Function End_Login_Script()
$lblStatus.Text = "Logon script complete. Thank you."
Sleep 1
EndFunction
Also, I completely redid my KixForms function (Copy/Register) how does it look?
Code:
Function Copy_KixForms()
$NetKixForms = $LocalDC + '\netlogon\kix\kixforms.dll'
$LocalKixForms = $SysFolder + '\kixforms.dll'
If Not Exist ($LocalKixForms)
Copy $NetKixForms $LocalKixForms /h /r
Shell 'regsvr32 /s ' + $LocalKixForms
EndIf
$NetVersion = GetFileVersion ($NetKixForms)
$LocalVersion = GetFileVersion ($LocalKixForms)
If $LocalVersion <> $NetVersion
Shell 'regsvr32 /u /s ' + $LocalKixForms
Copy $NetKixForms $LocalKixForms /h /r
Shell 'regsvr32 /s ' + $LocalKixForms
EndIf
EndFunction