No announcement yet.

Multiuse Logon Script

  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiuse Logon Script

    I'm trying to automate some tedious help desk tasks by making an all encompassing login script. The 3 main items that our help desk gets alot of calls on are mapping drives, installing printers, and setting up outlook profiles. What I want to do is make a vbs script that will do all of these things for them and thus reduce load. I have some questions though.

    Code for printer installs

    Set WshNetwork = WScript.CreateObject("WScript.Network")
    PrinterPath = "\\hqfile1\HQ Payroll HP P3005"
    WshNetwork.AddWindowsPrinterConnection PrinterPath

    Code for mapping drives

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "H:" , "\\hqfile1\apps"

    1. Is the code I have above the proper code for installing printers and mapping drives? Is there a more effective way?

    2. Can I make this a full time script that I associate in AD to existing and new users? I'm concerned about "overwriting" since this script will be set in each user's properties in AD. Do I need to add code that checks to see if something exists and skips if it does?

    3. Can I integrate the configuration of Outlook profiles by calling a .prf file as part of this script?

  • #2
    Re: Multiuse Logon Script


    A VBScript is perfect for what you want to accomplish.

    1. That code is correct for mapping a network drive and a printer. Side Note: I'll point out that in the printer code you have "WScript.CreateObject" and in the drive code you have "CreateObject". I just thought I'd point out that these two items do the exact same thing, when using "CreateObject" the "WScript" is optional. It is not optional when you do "WScript.Network".

    2. What do you mean by overwriting? What else might exist? You mentioned the profile so I'm not sure if you are talking about AD attributes or existing drives/printers on the local machine? If you're wondering about destroying existing connections, then yes some sort of code would be a great idea. This can be accomplished like so (from Guy's CP page):

    ' Already.vbs Windows Logon Script
    ' VBScript to map a network drive.
    ' Author Guy Thomas
    ' Version 1.7 - April 24th 2005
    '  ------------------------------------------------------' 
    Option Explicit
    Dim strDriveLetter, strRemotePath
    Dim objNetwork, objShell
    Dim CheckDrive, AlreadyConnected, intDrive 
    ' The section sets  the variables. 
    strDriveLetter = "W:" 
    strRemotePath = "\\alan\drivers" 
    ' This sections creates two objects:
    ' objShell and objNetwork and counts the drives
    Set objShell =  CreateObject("WScript.Shell") 
    Set objNetwork = CreateObject("WScript.Network") 
    Set CheckDrive = objNetwork.EnumNetworkDrives() 
    ' This section deals with a For ... Next loop
    ' See how it  compares the enumerated drive letters
    ' with strDriveLetter
    On Error Resume Next
    AlreadyConnected = False 
    For intDrive = 0 To CheckDrive.Count - 1 Step 2 
    If CheckDrive.Item(intDrive)  =strDriveLetter _
    Then AlreadyConnected =True
    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    If  AlreadyConnected = True then 
    objNetwork.RemoveNetworkDrive strDriveLetter 
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath 
    ' The first message box
    objShell.PopUp "Drive " &  strDriveLetter & _
    "Disconnected, then connected successfully." 
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath 
    objShell.PopUp "Drive " & strDriveLetter & _
    " connected  successfully." End if 
    ' Guy's Script ends here
    Let me know if that's not what you were talking about.

    Also, are you going to add this to the Profile tab of the User's properties? Would assigning the script to a GPO work better?

    3. Sorry, don't know about this one. A google search for "outlook profile vbscript" might work though?