VBS Logon Scripts
In the third installment of our seven-part series on scripting in Windows 2000 Active Directory, we look at writing a logon script using Visual Basic scripting.
VBS Logon Scripts
by Jim Hudson
This article is derived from Special Edition Using Active Directory, by Jim Hudson and Sean Fullerton(Que Publishing, November 2000).
Writing a VBS Logon Script for Windows 2000
Windows 2000 supports logon and logoff scripts that can be attached to any number of users through Group Policy. Unlike NT, however, we are not limited to .bat or .cmd files. We can also use VBScript through the Windows Scripting Host. This section is a demonstration and does not attempt to completely document all possibilities. Much additional information about Windows scripting can be found at http://msdn.microsoft.com/scripting.
Our example will use scripting to help set the environment for a user. We will map a network drive, connect to a printer, and load Internet Explorer into memory on the desktop. Our logon script is shown in the following listing.
NOTE
The single quote "'" character is simply one of the ways to document our scripts.
' declare variables dim wshnetwork dim ie ' suppress error messages on error resume next ' set reference to WSH network object set wshnetwork=wscript.createobject("wscript.network") ' remove network drive in case it is already in use wshnetwork.removenetworkdrive "z:" ' add network drive wshnetwork.mapnetworkdrive "z:","\\gold\dl" ' add connection to a network printer wshnetwork.addwindowsprinterconnection "\\gold\hp5" ' set new printer as default printer wshnetwork.setdefaultprinter "\\gold\hp5" ' set reference to Internet Explorer object set ie=createobject("internetexplorer.application") ' load microsoft home page ie.navigate"http://www.microsoft.com" ' make application visible ie.visible=true