Content-Type: text/html
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script Objective:
'
' To map network drive(s) to user workstation
'
'
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Created by: Troy D Murray
' Created on: 8/9/2006 @4:38p
' File name: MapNetworkPrinters2.vbs
' Notes: Initial script creation.
'
'
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Updated by:
' Updated on:
' File name:
' Notes:
'
'
'
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Header Section
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create variables for reference
'
On Error Resume Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Reference Section
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Assign variables their values or references
'
strComputer = "."
strOsVersion = ""
strDefaultPrinterNetworkUnc = ""
strPrinters = ""
' Add printer mappings here to include in the script when the user logs in
' NOTE: You must include a comma between the drive letter and
' path as well as a semi-colon at the end of the path!
strPrinters = strPrinters & "\\srvr-print1\F1_IS_DELL3100;"
strPrinters = strPrinters & "\\srvr-print1\F1_IS_DJ500;"
strPrinters = strPrinters & "\\srvr-print1\F1_IS_LJ5;"
strPrinters = strPrinters & "\\srvr-print1\F1_MAIL_LJ4050;"
strPrinters = strPrinters & "\\srvr-print1\F2_CLAIMS_LJ2500;"
strPrinters = strPrinters & "\\srvr-print1\F2_CLAIMS_LJ4250;"
strPrinters = strPrinters & "\\srvr-print1\F2_CLAIMS_RICOH2051;"
strPrinters = strPrinters & "\\srvr-print1\F2_FINANCE_LJ4000;"
strPrinters = strPrinters & "\\srvr-print1\F2_MBRSVC_LJ4250;"
strPrinters = strPrinters & "\\srvr-print1\F2_MBRSVCS_LJ5550;"
strPrinters = strPrinters & "\\srvr-print1\F2_PC_DELL5100;"
strPrinters = strPrinters & "\\srvr-print1\F2_PC_LJ4050;"
strPrinters = strPrinters & "\\srvr-print1\F3_EXECUTIVE_BI2300;"
strPrinters = strPrinters & "\\srvr-print1\F3_NBT_DELL5100;"
strPrinters = strPrinters & "\\srvr-print1\F3_NBT_RICOH;"
strPrinters = strPrinters & "\\srvr-print1\F3_SALES_LJ5500;"
strPrinters = strPrinters & "\\srvr-print1\PDF995Share;"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Worker Section
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' This section does the actual work of mapping printers
Set WshNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
strPrinters = Left(strPrinters,Len(strPrinters)-1)
For Each objOS in colOSes
strOsVersion = Split(objOS.Version,".")
Next
If strOsVersion(o) > 4 Then
If strOsVersion(1) > 0 Then
' This is a Windows XP workstation or newer, do the script
' Query WMI for a list of the printers on this workstation
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer WHERE Network = TRUE")
' Determine if the default printer is a network printer
For Each objPrinter in colInstalledPrinters
If objPrinter.Default = True Then
strDefaultPrinterNetworkUnc = objPrinter.Name
End If
Next
' Delete network printers from workstation
For Each objPrinter in colInstalledPrinters
WshNetwork.RemovePrinterConnection objPrinter.Name
Next
' Map network printers to workstation
strPrinters = Split(strPrinters,";")
For i = 0 To UBound(strPrinters)
If strPrinters(i) <> "" Then
WshNetwork.AddWindowsPrinterConnection strPrinters(i)
End If
Next
' If old default printer was network printer, reset it as default
If Len(strDefaultPrinterNetworkUnc) > 0 Then
WshNetwork.SetDefaultPrinter strDefaultPrinterNetworkUnc
End If
Else
' This is a Windows 2000 workstaion, do nothing
End If
End If