Logon Scripts

Logon Scripts - with VBScript

Introduction Logon Scripts

In this section I will give you examples of how to build the VBScript to use in your logon script.  I will help you chose which methods to use and which variables to change.  There are two sections; one section specialises in mapped network drives, while the other section deals with scripts for printers.  Please choose a Windows Logon Script to suit your particular task.

Map Network Drive Logon Scripts

Connect to Printers Logon Scripts

Guy Recommends: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server. Give this WMI monitor a try - it's free.

Download your free copy of WMI Monitor

Introduction to Logon Scripts with VBScript

When I first saw Windows 2003, I investigated the new features. I wondered:  'How do I assign logon scripts to users?'   I came up with two methods; the traditional NT 4.0 style or assigning VBScripts via Active Directory Group Policies.  (The traditional method was via the User's Properties, Profile tab.)

I even took a I step back and asked the more fundamental question:  'What am I trying to achieve here?'  The answer was, 'To provide users with the best environment for their work'. This lead me to investigate VBScript methods for providing mapped network drives and connecting to shared printers.

Good news.  Scripting possibilities improve dramatically when you progress from the old DOS batch files, to the new WSH with its rich VBScript verbs.  When you survey the big picture, you realize that Logon Scripts are only one of many jobs for WSH and VBScript. My point is that knowledge of these scripting objects, syntax and methods will help you automate other computer tasks.  As a bonus, if you master assigning Logon Scripts by Group Policy, then you will see how to apply other settings using Group Policy (GPMC)

Example of a Logon Script

VBScript to map a network drive.  Here are step-by-step instructions to create this logon script.

' MNDUserName.vbs
' VBScript to map a network drive to the UserName.
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.3 - April 24th 2010
' ----------------------------------------------------'
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUserName
strDriveLetter = "J:"
strRemotePath = "\\grand\home"

' Purpose of script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method. Result J: drive
Set objNetwork = WScript.CreateObject("WScript.Network")
' Here is where we extract the UserName
strUserName = objNetwork.UserName
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath _
& "\" & strUserName

' Extra code just to add a message box
WScript.Echo " Launch Explorer, check: "& strDriveLetter
WScript.Quit

' End of MapNetworkDrive Example logon script.

More Tasks for VBScript

WSH provides the objects, which our scripts then manipulate. Here are examples of the tasks that these objects and services can do for you:

  • Map network drives  (Then assign to Logon Script)
  • Connect to printers  (Then assign to Logon Script)
  • Manipulate Active Directory objects, e.g. Users passwords
  • Run basic functions such as CreateObject and GetObject
  • Modify environment variables e.g. Temp
  • Modify keys and values in the registry
  • Print a message to a Message Box on screen
  • Combine with WMI to measure and automate the operating system

Engineer's Toolset v10Guy Recommends: SolarWinds Engineer's Toolset v10

This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.

There are so many good gadgets; it's like having free rein of a sweetshop.  Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools.  Try the SolarWinds Engineer's Toolset now!

Download your fully functional trial copy of the Engineer's Toolset v10

What is WSH? (Windows Scripting Host)

Windows Scripting Host is aptly named; think of WSH as a butler who pampers their guests. When a logon script arrives from the server, WSH makes sure that all the objects and services that the script needs are available.  It also checks discretely for security and passes the script to the appropriate script engine, for example, ActiveX.

WSH is ideal for non-interactive scripting jobs, such as logon configuration, administrative scripting, or machine automation.  Let me take you on a journey where you create mapped network drives or printers.  Together we will study examples of VBScripts, object, method and properties model.

Site Home   • MapNetworkDrive (Basic Logon Script)    AddWindowsPrinterConnection

 

Download my Logon Script eBook for only $6.25

Logon ScriptThe extra features you get in your eBook include, more pages full of detailed examples.  Also, ten 'how to...' sections, with screen shots showing which menus to use.  Go for Guy's eBook - and get a printable version with copy enabled and no expiry date.

  Jumbo Script 7 Package

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2017 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: