An extract from ours is:
Code:
on error resume next
Set shell= WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
dim Counter, PrinterPath
dim strResult, strLocation, strComputer
'Remove All Network Printers.
Set oPrinters = WshNetwork.EnumPrinterConnections
FOR Counter = 0 to oPrinters.Count - 1
IF mid(oPrinters.Item(Counter), 1, 2) = "\\" THEN
PrinterPath = oPrinters.Item(Counter)
WshNetwork.RemovePrinterConnection PrinterPath, True, True
End If
Next
'Add Network Printers based on Location set in Environment Variables
strLocation = shell.ExpandEnvironmentStrings("%LOCATION%")
strComputer = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
select case strLocation
case "ASTLaptop"
addPrinter "\\server2\hplassta",true
case "ITOffice"
addPrinter "\\server2\HP4100IT",true
addPrinter "\\server2\copyroom1232",false
addPrinter "\\server2\ILCStudent",false
end select
function addPrinter(strConnectString,isDefault)
if strConnectString <> "" then
strResult = WshNetwork.AddWindowsPrinterConnection(strConnectString)
if isDefault then
WshNetwork.SetDefaultPrinter strConnectString
end if
end if
end function