Logon Scripting 101

What is the benefit of a Logon script?

Logon scripts allow you to run a script when the user logs into the domain. There are lot's of reasons why you would want a script to run at this time; to map drives and printers that the user needs, check for varous values such as what version of anti-virus software is running, or even the AV Dat version, the list goes on and on.

For example: KEN is in the Sales group, and the Sales group has access to certain file shares and printer shares, and it's very easy to mount these drives and connect to these printer for Ken no matter which computer he signs onto the domain with if your using a logon script.

Making a script, then assigning it to a user or group

A logon script is sometimes called a batch file, which is because the file typically ends with the extension .bat A batch file is easy to write, all you do is open a text editor such as notepad or wordpad, write the script, save the file as a .txt extension and rename that extension from ".txt" to ".bat"

Getting Started

This is a very simple example of a logon script that will mount three network drives and three networked printers. The script will send "Net send" alerts to the user account "SiteAdmin" if any of the printers have trouble getting assigned. For a good list of the variables that you can call in windows scripts look here: Windows Variables These are the variables such as %time% %date% %username% %logonserver% and many more.

***NOTE*** the word "rem" means remark, it's ignored by the script except by "echo" commands which will just print the line, but not run anything from the line.

@echo off
rem echo is off, unless specified on the line
echo +----------------------------------------------+
echo +-------------- Mapping Drives ----------------+
echo +----------------------------------------------+
net use m: \\SalesFiles\Marketing\Ken
net use u: \\SalesData\User\Ken
net use r: \\SalesFiles\Marketing\Resources
echo Synchronizing system clock with time server...
net time \\NTPServer /set /yes
con2prt /c \\SalesData\Letter-HD
if errorlevel 0 goto Clj-1
net send SiteAdmin %username% had an error connecting Letter-Head Printer at %time% %date%
con2prt /c \\SalesData\Color-LJ1
if errorlevel 0 goto Bw-lj3
net send SiteAdmin %username% had an error connecting Color-LaserJet-1 Printer at %time% %date%
con2prt /c \\SalesData\BlkWht-LJ3
if errorlevel 0 goto done
net send SiteAdmin %username% had an error connecting Black-White-Laser-Jet-3 Printer at %time% %date%
echo Done!

More Advanced Scripting- Scripting 102

Click on the link to go to the more advanced logon scripting guide

Next goto Logon Scripting 102