Home > Articles > Operating Systems, Server > Microsoft Servers

📄 Contents

  1. VBS Logon Scripts
  2. Logon Script Line by Line
  • Print
  • + Share This

Logon Script Line by Line

This logon script simply does three things. It maps the z: drive to the dl share on server gold, it maps to and sets as default printer the hp5 printer on server gold, and it loads the Internet Explorer application with the www.microsoft.com page loaded. Let's walk through the script one line at a time and talk about what happens.

'declare variables

In the `declare variables section, we are setting aside space in memory for our two variables, wshnetwork and ie. Notice that we are not declaring the variables as a particular data type. That is because, in VBScript, we get only one datatype, and that is variant. It is not necessary to declare the datatype.

'suppress error messages

The `suppress error messages section is really quite interesting. The on error resume next command tells the script that rather than halting on any error (the default behavior), it should suppress error messages and continue the script.

NOTE

Do not enable the on error resume next command during the creation and debugging of the scripts. If you do and you have problems with your script, it will simply die and you will never receive any error output of any kind. If you have this command in your script, comment it out with an "`" and then enable it when you are ready to distribute the script.

The reason that we need the on error resume next command is that if we try to add a network drive that is already mapped to z:, we receive an error and the script terminates. If we do not have z: mapped and we try to remove it, we receive an error and the script terminates (seems perversely predictable, doesn't it?). This command allows us to set the commands and recover from inevitable errors.

'set reference to WSH network object

The `set reference to WSH network object section loads the wscript.network object into memory. When we call this code, what actually happens is that the wscript.network progid is used to find the clsid (HKEY_CLASSES_ROOT\CLSID\{F935DC26-1CF0-11D0-ADB9-00C04FD58A0B}). One of the properties of the clsid is the inprocserver32 key. This is a fully qualified pathname to the DLL \WINNT\System32\wshom.ocx. This DLL is then loaded into memory, and the methods of this COM object are available to us. Conceptually, the same thing happens when we load the InternetExplorer.Application object. The process we are causing here is called instantiation. It is simply loading a COM object into memory and establishing a relationship with it so that we can use its functionality.

'remove network drive in case it is already in use

The `remove network drive section makes sure that another network connection is not using the z: drive that we want to use. The command is simple and takes one parameter, the drive letter that we want to free. Part of the point of this logon script is to provide the same environment every time we log on. Because it is possible to create persistent network connections either at the command line or with the Internet Explorer, we use this command to make sure that another network connection is not currently attached to this drive letter.

'add network drive

The `add network drive section takes two parameters, the letter that we want to attach this to and the sharename that we want to attach. We will need to make sure beforehand that the share is available and that the intended user has sufficient permissions to use the share.

'add connection to a network printer

This section takes one parameter, the Universal Naming Convention (UNC) of the printer share. Make sure that you use the addwindowsprinterconnection method rather than the old WSH 1.0 addprinterconnection method. The old version does not work well with Windows 2000.

'set reference to Internet Explorer object

This section of code instantiates the IE application object and makes it available to us.

'load microsoft home page

This code uses the navigate method of the IE object to load the Microsoft home page or any page you choose. A good choice for this parameter would be an informational page on your corporate intranet that is updated daily with information that your users need.

'make application visible

Because many COM objects run without a visible component, it is necessary to explicitly make the application visible.

It is not necessary to become a Visual Basic programmer to take advantage of Group Policy. There are literally hundreds of configurable options that require absolutely zero coding. I believe, however, that in the future, the mark of an experienced, professional Windows 2000 manager will be a facility with a scripting language. There are many situations that respond very well to scripting, whether it is logon scripts as shown here or the multitude of scenarios that can be answered through administrative scripting.

We have just grazed the surface of what is possible with logon scripts. The entire Windows 2000 and Office 2000, and Windows Management Instrumentation (WMI), object models are open to us using the Windows Scripting Host. The WSH programming environment is very well documented on the Microsoft Developer Network site, as well as many other third-party sites throughout the Internet. In the next installment, we will see how to attach this script to all the computers in an organizational unit through Group Policy.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.