Page 1 of 1 1
Topic Options
#135151 - 2005-03-09 07:11 PM Kix Newbie... Feel like looking over my script?
Anonymous
Unregistered


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


Top
#135152 - 2005-03-09 11:08 PM Re: Kix Newbie... Feel like looking over my script?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
My guess is that the moderator that moved this here did not consider that Anonymous posting is not allowed in the scripts forum.

I really didn't see the problem with it staying in the Starters forum.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135153 - 2005-03-09 11:26 PM Re: Kix Newbie... Feel like looking over my script?
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

My guess is that the moderator that moved this here did not consider that Anonymous posting is not allowed in the scripts forum.

I really didn't see the problem with it staying in the Starters forum.



Me neither... but oh well, I am finally registered and that is my script above, any comments/suggestions?

Chris

Top
#135154 - 2005-03-09 11:50 PM Re: Kix Newbie... Feel like looking over my script?
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Hi dataspike welcome:
Your loginscript looks nice and tidy I wish I had started writing that way. I find Set_IE_Limits() intresting.

Just a question? Arent you writing a log file?
_________________________
Life is fine.

Top
#135155 - 2005-03-10 12:08 AM Re: Kix Newbie... Feel like looking over my script?
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
I see now.
LOGINFO($FILE,$STRING).

You could just write a log file like this.
Fe:
Code:
  
If Open(1,"\\SERVER\NETLOGON\Database\logon.txt",5) = 0
WriteLine(1, @ProductType + "," + @day + "," + @time + "," + @lserver + "," + @ipaddress0 + "," + @WKSTA + "," + @userid + "," + @PrimaryGroup + Chr(13)+Chr(10))
EndIf



And on and on with macros and stuff. Maybe after, schedule a process to import it to a database.

Another tip:
There will be a moment wich you might consider using a main script (maybe encrypted in the future) from where you call all the functions you add. That way you can keep the order.
_________________________
Life is fine.

Top
#135156 - 2005-03-10 01:17 AM Re: Kix Newbie... Feel like looking over my script?
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
For your KixForms Function, you have:

$SysFolder

I don't see that being passed to the function nor is it defined there.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#135157 - 2005-03-10 01:51 AM Re: Kix Newbie... Feel like looking over my script?
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

For your KixForms Function, you have:

$SysFolder

I don't see that being passed to the function nor is it defined there.

Kent





Yeah, I actually moved it up towards the top in this section... Since I use it in other place (or will) no need in using extra lines since it should never be re-declared.

Chris

Code:

;*******************************************************************************
;** Constant Variables
;*******************************************************************************
$RegistryCheck = "HKLM\Software\Company Name"
$SysFolder = %WinDir% + '\system32'
$LocalDC = "\\domain-dc01"


Top
#135158 - 2005-03-10 01:54 AM Re: Kix Newbie... Feel like looking over my script?
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

Hi dataspike welcome:
Your loginscript looks nice and tidy I wish I had started writing that way. I find Set_IE_Limits() intresting.

Just a question? Arent you writing a log file?




Yeah, the Set_IE_Limits, that's caused some question here... We basically are preparing for another AD Migration and have found by clearing out the Temp Files, and setting the limits as I have, make it easier when we migrate the machines to the new AD domain, as it has less files to worry about. But it also gave us a chance to keep users from trying to be sneaky and prevent them clearing their internet history.

Thanks all... Anyone else have any comments suggestions?

I'd like to work on some error handling, but I have no idea how to even start that task. Insight there would be awesome.

Thanks again,
Chris

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.066 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org