;*************************************************************************
; Script Name: Generic Logon Script
; Script Version: 1.2
; Author: Luke
; Date: 19/02/2008
; Description: This script is run during logon.
; It maps drives, printers and calls other scripts
; such as audit wizard and wireless.
; Changelog: 1.0 - Initial Release (14/02/2008)
; 1.1 - Improved Logging, switch at top of the page.
; - Replaced 'Case' statements with IfThenElse
; 1.2 - Added Variable passing of $nasip to wireless script
;*************************************************************************
$enablelogging = 0 ;Change to 1 to enable logging, pipes output to c:\temp\[username].txt, ensure priviliges are sufficent.
;Leave at 0 during normal operation
;NOTE: For best viewing, disable word wrap
;====================================================================================================
; VARIABLES
; ---------
;In this section, ALL used variables should be declared.
;Comment any variable which is not self explanitory, and group like variables together
;Keep variable names all in lowercase
;Before ever deleting or renaming a variable, search for it as it may be called in multiple sections
;====================================================================================================
;-----------------------------
;Common Variables
;May be used in multiple areas
;-----------------------------
$domain = @DOMAIN ;Returns the DFS name of the server, such as [domain] or [domain2]
$servername = @LSERVER + "\" ;@LSERVER returns \\servername of AD server such as "\\[an AD server name]"
$netlogon_path = $servername + "NETLOGON\"
$nasip = "[insert NAS Server IP address here]" ;Required to call Wireless Script
;------------------------
;Mapped Printer variables
;------------------------
;Printer Groups
$printgroup1 = "[PrinterGroupName]"
$printgroup2 = "[PrinterGroupName]"
$printgroup3 = "[PrinterGroupName]"
;Printer Paths
$printer1 = $servername + "[PrinterShareName]"
$printer2 = $servermame + "[PrinterShareName]"
$printer3 = $servername + "[PrinterShareName]"
;-----------------------
;Mapped Drive Variables
;-----------------------
;Drive Groups
$drivegroup1 = "[Drivegroup1]"
$drivegroup2 = "[Drivegroup2]"
$drivegroup3 = "[Drivegroup3]"
$drivegroup4 = "[Drivegroup4]"
;Drive Paths
$drivepath1 = $servername + "ShareName"
$drivepath2 = $servername + "ShareName"
$drivepath3 = $servername + "ShareName"
$drivepath4 = $servername + "ShareName"
;-------------------------
;Wireless Script Variables
;-------------------------
$wirelessgroup = "[Wireless Group Name]"
$inipath = "c:\temp\variables.ini"
;-------------------------
;Event Logging Variables
;-------------------------
$logpath = "c:\temp\" + @USERID + ".txt"
$extralogcommands = '%comspec% /c "IPCONFIG /all >> $logpath"' ;Executed if $enablelogging = 1
$index = 0 ;Loop Counter
;============================================================
; Logging
;Pipes output to c:\temp\[username].txt
;Overwite enabled by '1' switch
;To enable, set $enablelogging to 1, at top of script
;Also executes $extralogcommands and appends it to $logpath
;============================================================
IF $enablelogging = 1
REDIRECTOUTPUT($logpath,1)
? " "
? "----------------------------------"
? "Session Information:"
? "----------------------------------"
? " "
? "User ID: " + @USERID
? "Domain: " + @DOMAIN
? "Date: " + @DATE
? "Time: " + @TIME
? "Computer Name " + @WKSTA
? "OS Version " + @PRODUCTTYPE
? "Logon Server " + @LSERVER
SHELL $extralogcommands
? "----------------------------------"
? " "
? "---------------------------------"
? "User: " @USERID " is a member of:"
? "---------------------------------"
;Loop to output groups the USER is a member of
DO
$group = ENUMGROUP($index)
$index = $index + 1
if LEN($group) > 2
? "-> " $group
ENDIF
UNTIL Len($group) = 0
ENDIF
;--------------------------------------------------
; Map Printers
; ------------
;Maps printers by Passing the Printername to the
;Function "computeringroup"
;--------------------------------------------------
IF computeringroup($printgroup1,$domain)
mapprinter($printer1)
ENDIF
IF computeringroup($printgroup2,$domain)
mapprinter($printer2)
ENDIF
IF computeringroup($printgroup3,$domain)
mapprinter($printer3)
ENDIF
;--------------------------------------------------
; Map Drives
; ----------
;Maps printers by Passing the drivepath and letter
;to the Function "mapdrive"
;--------------------------------------------------
IF ingroup($drivegroup1)
mapdrive($drivepath1,"[DriveLetter]")
ENDIF
IF ingroup($drivegroup2)
mapdrive($drivepath2,"[DriveLetter]")
ENDIF
IF ingroup($drivegroup3)
mapdrive($drivepath3,"[DriveLetter]")
ENDIF
IF ingroup($drivegroup4)
mapdrive($drivepath4,"[DriveLetter]")
ENDIF
;--------------------------------------------------
; Calls the Wireless Script
;--------------------------------------------------
?"netlogon path is: " $netlogon_path
IF computeringroup($wirelessgroup,$domain)
?"Computer is in the correct group ($wirelessgroup) to recieve Wireless Settings"
?"Creating INI file..."
WRITEPROFILESTRING("c:\temp\variables.ini", "vars", "nasip", $nasip)
IF @error = 0
?"INI created Successfully!"
ELSE
?"INI NOT created succesfully, error code: " @ERROR
?"Skipping wireless script"
GOTO "EndWirelessScript"
ENDIF
?"Running Wireless Script...."
RUN "%comspec% /c " + $netlogon_path + "CPAU.exe -dec -file " + $netlogon_path + "wireless.job -lwop"
ENDIF
:EndWirelessScript
;--------------------------------------------------
; Calls the Audit Wizard Script
;--------------------------------------------------
RUN "%comspec% /c " + $netlogon_path + "CPAU.exe -dec -file " + $netlogon_path + "audit.job -lwop"
?"Running Audit Wizard Script..."
;******************************************************************************
;/////////////////////////////////////////////////////////////////////////////*
;\\\\\Called Functions, DO NOT MODIFY!!!!!!!!\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
;/////As it may prevent large sections of the above script from working///////*
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
;******************************************************************************
;--------------------------------
;Called to check group membership
;--------------------------------
Function ComputerInGroup($group1,$domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group1 + ",group" )
if @error exit 1 endif
if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction
;---------------------
;Called to Map Printer
;---------------------
function mapprinter ($printer)
if ADDPRINTERCONNECTION ($printer) = 0
? " Printer " $printer " added successfully"
else
?"*************************************************"
?"Printer (" $printer ") was not added successfully!!!!!"
?"Please contact the IT Department"
?"*************************************************"
Sleep 5
endif
endfunction
;---------------------
;Called to Map Drive
;---------------------
function mapdrive ($drivepath,$driveletter)
Use $driveletter $drivepath
If @ERROR=0
?"Drive: " $drivepath " was mapped successfully!"
ELSE
?"*************************************************"
?"Drive ( $drivepath ) was NOT mapped!!!!!"
?"Please contact the IT Department"
?"*************************************************"
Sleep 5
ENDIF
endfunction
;******************************************************************************
;/////////////////////////////////////////////////////////////////////////////*
;\\\\\\\\\\\\\\\\\\\\\\END OF CALLED FUNCTIONS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
;/////////////////////////////////////////////////////////////////////////////*
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
;******************************************************************************