Login Scripts Guide – Part II
Last time around we learnt how to make a simpleÂ login script and assign it to users which demonstrated the time saving potential of a login script.
For this lesson we are going to learn how to use MicrosoftÂ VBScript login scripts to perform some more advanced operations and also how to implement the script into a group policy.
Creating and linking your script to a group policy
Open up Active directory and computers and right click your chosen Organisational Unit (herein referred to as an OU) and click properties. You should see four tabs across the top, the one you are looking for is group policy.
On the group policy tab you should see a linked group policy object, if not you can create one by clicking the new button and giving it a name. Once named you should click options then click the no override option and press ok.
Now click the edit button and you should be presented with the Group Policy Object Editor (Pictured below)
Now we need to navigate down the tree to User Configuration->Windows Settings->Scripts
You should now see two options, logon and logoff. Right click logon and click properties.
At the bottom of the dialog box you should see a button labeled “show files” and this will open up the folder where you need to create your script file for it to be linked to your OU. For this example create a new text document and rename it to site1.vbs and close the folder back down (make sure that the icon changes if hide extensions is on you might end up with a double extension!).
Now click the add button and then browse to select the script you just created, when you press the ok button you should see your script in the list. When you have finished adding your script file to the group policy press ok and then close down the editor.
At this point it is a good idea to refresh your policies. To do this open a command prompt and then run the gpupdate /force command. You should see a “Refreshing Policy” confirmation. This means that all machines now when they log on should use your new settings.
Writing your script
Open up your script file in notepad. (you can find this fileÂ in the logon settings in the group policy editor, see above and clicking show files.)
You should now have your blank canvas in front of you!
Whilst writing your script it is a good idea to use comments so that if there is a problem you know what section of the script does what. Its also useful if your colleagues come to edit the script in the future. Comments in vbscript can be added with the apostrophe character
‘ Site 1 Login Script – My Company
‘ Last updated by Ben Gillam (12/4/08)
‘ Map Network drives.
Writing in sections with comments is good practice to get into and will make your life much easier if you have to weed out any silly bugs in your script.
Performing general tasks with vbscript
One of the most common tasks that you would normally use a script for is attaching mapped network drives so your users can get to their data.
The command in vbscript is a little more complex than the batch file equivalent.
Set objNetwork = CreateObject(“WScript.Network”)
strDriveLetter = “J:”
strHomeServer = “\\server\jobs”
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer
This command will map J: to \\server\jobsÂ and although thisÂ might look pointlessly complex compared to theÂ batch file method it allows for more flexibility for custom error messages or indeed success messages. For example you could confirm that everything went ok by using a command such as.
Wscript.Echo “Drive ” & strDriveLetter & ” sucsessfully mapped to ” & strHomeServer
This will display a message on logon that says “Drive J: successfully mapped to \\server\jobs.
Connecting to shared printers
To connect to shared printers there is also an objNetwork command.
Set objNetwork = CreateObject(“WScript.Network”)
You can use as many of these commands as you like to set up multiple printers and you will probably want to set a default printer. This command would be quite useful if your Active Directory is well organised into departments, eg the finance department has its own OU and so does the sales department so you can set the default printer automatically for users in that department/office by modifying your script and linking with the other OU.
The above command should be fairly self explanatory.Â You can also use the printers name e.g “HP Color Laserjet 3800″ but I would recommend using just the UNC path and sometimes printer names will change with a change of driver breaking your script, Â whereas theÂ UNC pathÂ would not.
Hopefully this should have provided a simple insight into how to get your login scripts up and running and making day to day changes easier to implement to lots of computers very quickly.
(I have tested these snippets on a few computers and they work ok for me, I’m no vbscript expert but if you have any problems please drop me a comment)