Here, SDAT is a variable containing the complete path and file name of the SuperDAT executable; DAT is a variable containing the complete path and file name of the DAT executable; NAILOG is a variable containing the complete path and file name of the status log text file; and DDAY is the day of the week (Mon, Tue, Wed, Thu, Fri, Sat, Sun) to run the SuperDAT as opposed to the daily DAT file. Updating Norton Antivirus Files To update your Norton antivirus files with shell scripting, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download the latest Intelligent Updater file from www.symantec.com to the new directory. 3. Select Start|Run and enter “scriptfile.bat”. Here, scriptfile is the full path and file name of a script file that contains the following: @Echo Off Set IUPDATER=iufile %IUPDATER% /Q > Nul Here, IUPDATER is a variable containing the complete path and file name of the Intelligent Updater executable. Creating Logon Scripts with KiXtart KiXtart is a powerful scripting tool primarily focused and used for logon scripts. KiXtart contains many built-in methods and macros to retrieve quick information; other scripting languages would require external tools or extensive scripting to retrieve the same information. Setting Up the Environment When creating a logon script, it is important to make sure the script looks and feels as it was intended. KiXtart includes several commands to customize the logon script environment. To set up a customized logon script environment using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: CLS ; Clear screen BREAK OFF ; Logoff user when attempt to close logon box $RCODE = SETCONSOLE("ALWAYSONTOP") ; Set box on top $RCODE = SETASCII("ON") ; Turn on ASCII characters This script first clears the screen (CLS) and sets the logon script box to log off the current user if he/she attempts to close the box. The logon script box is then set to be on top of all other windows. The final command turns on ASCII characters. This is a new feature included with KiXtart 3.62 and higher that allows you to change the look of text by turning ASCII on or off. Changing the Background and Foreground Colors KiXtart supports the color command to change the background and foreground in a shell prompt. The basic syntax of the color command is as follows: COLOR Fx/By Here, F is the foreground color value, x is an optional indicator to increase the color intensity if a plus sign (+) is specified, B is the background color value, and y is an optional indicator that causes the background to blink if a plus sign (+) is specified. The color command supports the following color values: N—Black B—Blue G—Green C—Cyan R—Red M—Magenta Y—Yellow/Brown W—White Here is an example to change the shell prompt colors to bright white text on a blue background: COLOR W+/B Synchronizing the Local System Time Synchronizing the local system to a central time source allows you to perform enterprise-wide tasks simultaneously. KiXtart includes the SetTime command to synchronize the local system time to a time source. The basic syntax of the SetTime command is as follows: 1. SetTime source Here, source is any one of the following types: \\Server—Specifies the name of a time source server DomainName—Searches the specified domain for a time source “*”—Specifies to search the local domain for a time source The following script attempts to sync the local system time with the logon server. If this fails, the domain will be searched for a time source to sync with. To execute this script, proceed as follows: Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: ? "Syncing the time with @LSERVER…" SETTIME "@LSERVER" If @ERROR <> 0 ? "Searching the local domain for a time-server…" SETTIME "*" If @ERROR <> 0 ? "Time Sync Error" Else ? "Sync Successful" EndIf EndIf Mapping Universal Drives Mapping common drives for all users allows you to present a central resource location for applications or data. In Chapter 7, you learned how to map network drives from within Windows and the command prompt. KiXtart includes the use command, similar to the Net Use command, to attach a drive letter to a network share. To map a network drive and display the status using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: $Drive="DriveLetter" $Share="\\server\sharename" ? " Mapping drive $Drive to $Share" Use " $Drive: " /Delete Use " $Drive: " $Share If @Error = 0 ? " Map Successful" Else ? " Error mapping drive $Drive to $Share" EndIf Here, driveletter is the drive letter to map a share to, and server contains the sharename you want to map to. Mapping Drives by Group Mapping drives by group membership allows you to control which drives and resources will be available to which users. KiXtart includes the InGroup command, similar to the IfMember resource kit utility, to determine group membership. To map a network drive according to group membership and display the status using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: $Drive="DriveLetter" $Share="\\server\sharename" If InGroup("GroupName") ? "Mapping drive $Drive to $Share" Use "$Drive: "/Delete Use "$Drive: "$Share If @Error = 0 ? "Map Successful" Else ? "Error mapping drive $Drive to $Share" EndIf EndIf Here, GroupName is the name of the group to check membership; driveletter is the drive letter to map a share to; and server contains the sharename you want to map to. Mapping Printers Mapping printers through a logon script provides an easy method to remotely update printer connections. KiXtart contains several commands to add, remove, and set default printers. To map a printer using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: $Pserver="Server" $DPrinter="Printer" If AddPrinterConnection("\\$PServer\$DPrinter") = 0 ? "Added printer $DPrinter" Else ? "Error adding $DPrinter" EndIf Here, pserver is the variable holding the printer server name, and dprinter is the variable holding the name of the printer share. Checking for Remote Access Determining whether a client is logging in through the network or remote access helps you specify which parts of the script to run. KiXtart includes the @RAS macro to the number of remote access connections. To determine whether a user is logging on through remote access using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: If @RAS = 0 ? " You are logging in through the local network. " Else ? "You are logging on through remote access" EndIf Displaying Time-Based Greetings Although it’s not essential, many administrators like to display a greeting to the user depending on the time of day. To display a time-based greeting using KiXtart, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: SELECT CASE ((@TIME > "00:00:00") AND (@TIME < "12:00:00")) ? "Good Morning @FULLNAME" CASE ((@TIME > "12:00:00") AND (@TIME < "18:00:00")) ? "Good Afternoon @FULLNAME" CASE 1 ? "Good Evening @FULLNAME" Updating McAfee Antivirus Files 1. ENDSELECT Here, the @TIME macro indicates the current time, and @FULLNAME indicates the full name of the current user. To update your McAfee antivirus engine and/or signature files with KiXtart, proceed as follows: Create a new directory to store all files included in this example. 2. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: $SDAT="superdat" $DAT="datfile" $NAILOG="textlog" $DDAY="DOTW" If @DAY = $DDAY SHELL "%COMSPEC% /C $SDAT /F /PROMPT /REBOOT /SILENT /LOGFILE $NAILOG" Else SHELL "%COMSPEC% /C $DAT /F /PROMPT /REBOOT /SILENT /LOGFILE $NAILOG" EndIf Here, SDAT is a variable containing the complete path and file name of the SuperDAT executable; DAT is a variable containing the complete path and file name of the DAT executable; NAILOG is a variable containing the complete path and file name of the status log text file; and DDAY is the day of the week (Monday-Sunday) to run the SuperDAT as opposed to the daily DAT file. Updating Norton Antivirus Files To update your Norton antivirus files with KiXtart, proceed as follows: 1. 2. Create a new directory to store all files included in this example. Download the latest Intelligent Updater file from www.symantec.com to the new directory. 3. Download and extract the latest version of KiXtart, from www.microsoft.com , to the new directory. 4. Select Start|Run and enter “kix32 scriptfile”. Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following: $IUPDATER = "iufile" SHELL "%COMSPEC% /C $IUPDATER /Q" Here, IUPDATER is a variable containing the complete path and file name of the Intelligent Updater executable. Creating Logon Scripts with Windows Script Host Windows Script Host is a relatively new scripting language and is rather limited with logon scripts. Although you can call external functions or custom COM objects to perform specific logon script tasks, WSH does not contain many of the standard logon script functions other scripting languages may have, such as a time synchronization command. Synchronizing the Local System Time Windows Script Host does not have a time synchronization command to sync the local system time with a network time source. You can use the shell run command to call external commands, such as the Net Time command, and use a return variable to indicate whether the command was successful. The following script attempts to sync the local system time with the server named servername using the Net Time command. If this synchronization fails, the domain will be searched for a time source to sync with. To execute this script, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Set SHELL = CreateObject("WScript.Shell") TServer="ServerName" Wscript.Echo "Syncing the time with " & TServer & "…" ELevel = Shell.Run("Net Time \\" & TServer & " /Set /Yes",0,True) If (ELevel <> 0) Then Wscript.Echo "Searching the local domain for a " & _ time-server…" ELevel = Shell.Run("Net Time /Set /Yes",0,True) If (ELevel = 0) Then Wscript.Echo "Sync Successful" Else Wscript.Echo "Time Sync Error" End If Else Wscript.Echo "Sync Successful" End If Note The highlighted code above must be placed on one line. Mapping Universal Drives Mapping common drives for all users allows you to present a central resource location for applications or data. In Chapter 7, you learned how to map network drives from within Windows and the command prompt. You can use the Windows Script Host network object to attach a drive letter to a network share. To map a network drive and display the status using Windows Script Host, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Network.MapNetworkDrive Drive, Share Else 1. Set Network = CreateObject("WScript.Network") Drive = "DriveLetter:" Share = "\\server\sharename" Wscript.Echo "Mapping drive " & Drive & " to " & Share If Err.Number = 0 Then Wscript.Echo "Map Successful" Wscript.Echo "Error mapping drive " & Drive & " to " & _ Share End If Here, driveletter is the drive letter to map a share to, and server contains the sharename you want to map to. Mapping Drives by Group Mapping drives by group membership allows you to control which drives and resources will be available to which users. Windows Script Host does contain a method to determine group membership. Although you can use the ADSI IfMember method, this method can be slow on larger networks. Alternatively, you can use the WSH shell run command to call external commands, such as the IfMember resource kit utility, and use a return variable to indicate whether the command was successful. To map a network drive according to group membership and display the status using Windows Script Host, proceed as follows: Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Set SHELL = CreateObject("WScript.Shell") Set Network = CreateObject("WScript.Network") Drive = "DriveLetter:" Share = "\\server\sharename" DGroup = "groupname" ELevel = Shell.Run("fullpath\IfMember " & DGroup,0,True) If (ELevel = 1) Then Wscript.Echo "Mapping drive " & Drive & " to " & Share Network.MapNetworkDrive Drive, Share If Err.Number = 0 Then Wscript.Echo "Map Successful" Else Wscript.Echo "Error mapping drive " & Drive & " to " & _ Share End If End If Here, fullpath is the full path where the IfMember utility is located; GroupName is the name of the group to check membership; driveletter is the drive letter to map a share to; and server contains the sharename you want to map to. Mapping Printers Mapping printers through a logon script provides an easy method to remotely update printer connections. Starting with version 2, Windows Script Host provides several commands to add, remove, and set default printers. To map a printer using Windows Script Host, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next PServer = "Server" DPrinter = "Printer" Port = "LPT1" Set Network = CreateObject("Wscript.Network") Network.AddPrinterConnection Port, "\\" & PServer & "\" & Printer If Err.Number <> 0 Then Wscript.Echo "Added printer " & Printer Else Wscript.Echo "Error adding printer " & Printer End If Note The highlighted code above must be placed on one line. Here, pserver is the variable holding the printer server name, and dprinter is the variable holding the name of the printer share. Tip You can use the AddWindowsPrinterConnection method to add printers to Windows NT/2000 systems without having to supply a port. Checking for Remote Access Determining whether a client is logging in through the network or remote access helps you specify which parts of the script to run. Windows Script Host does not contain a method to detect remote access connections. CheckRAS is a command-line, SMS resource kit utility to determine whether a user is using remote access. To determine whether the current user is using remote access during a logon script using Windows Script Host, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Set SHELL = CreateObject("WScript.Shell") ELevel = Shell.Run("fullpath\CheckRAS",0,True) If (ELevel = 0) Then RAS = "YES" Else RAS = "NO" End If Here, fullpath is the full path where the CheckRAS utility is located, and RAS indicates whether the current user is using remote access or not. Displaying Time-Based Greetings 1. Although it’s not essential, many administrators like to display a greeting to the user depending on the time of day. To display a time-based greeting using Windows Script Host, proceed as follows: Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next ElseIf Hour(Now) < 18 Then If Hour(Now) < 12 Then Wscript.Echo "Good Morning" Wscript.Echo "Good Afternoon" Else Wscript.Echo "Good Evening" End If Updating McAfee Antivirus Files To update your McAfee antivirus engine and/or signature files with shell scripting, proceed as follows: 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host from www.microsoft.com to the new directory. 3. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Set SHELL = CreateObject("WScript.Shell") SDAT="superdat" DAT="datfile" NAILOG="textlog" DDAY="DOTW" If WeekDayName(WeekDay(Date)) = DDAY Shell.Run CHR(34) & SDAT & CHR(34) & " /F /PROMPT /REBOOT /SILENT /LOGFILE NAILOG",1,True Else Shell.Run CHR(34) & DAT & CHR(34) & " /F /PROMPT /REBOOT /SILENT /LOGFILE NAILOG",1,True EndIf Note Chr(34) translates the ASCII code character 34 into a quotation mark (“). This is necessary when using the Shell.Run command with long file names. Here, SDAT is a variable containing the complete path and file name of the SuperDAT executable; DAT is a variable containing the complete path and file name of the DAT executable; NAILOG is a variable containing the complete path and file name of the status log text file; and DDAY is the day of the week (Monday-Sunday) to run the SuperDAT as opposed to the daily DAT file. Updating Norton Antivirus Files To update your Norton antivirus files with Windows Script Host, proceed as follows: 1. 2. Create a new directory to store all files included in this example. Download the latest Intelligent Updater file from www.symantec.com to the new directory. 3. Download and install the latest version of Windows Script Host, from www.microsoft.com , to the new directory. 4. Select Start|Run and enter “cscript scriptfile.vbs”. Here, scriptfile is the full path and file name of a script file that contains the following: On Error Resume Next Set SHELL = CreateObject("WScript.Shell") . the Intelligent Updater executable. Creating Logon Scripts with Windows Script Host Windows Script Host is a relatively new scripting language and is rather limited with logon scripts. Although. within Windows and the command prompt. You can use the Windows Script Host network object to attach a drive letter to a network share. To map a network drive and display the status using Windows. the standard logon script functions other scripting languages may have, such as a time synchronization command. Synchronizing the Local System Time Windows Script Host does not have a time synchronization