problems with my printer Script, can you cast your eye over it?
I keep get intermittent problems with the script we have been running for a longtime. It's normally flawless but now for some reasons I get errors.
* Sometimes the correct printers are shown and loaded sometimes they are not.
*pretty much everyone gets an erroneous printer which does not exist and is not in the script, from one of our old servers, can not find anywhere where it is running.
Keep getting script errors:
Script: xxxxxxxx
Line: 10
Char: 5
Error: Generic
Code: 80041001
Source: SWBemOBJECTEx
Script is below, Thanks :
Code:
'This Deletes all mapped printers for the user
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
'***********************************************
'This checks the name of the machine and applies the printer path
Dim oNetwork, sPrintPath, sShort
Set oNetwork = CreateObject("WScript.Network")
sShort = Left (oNetwork.ComputerName, 4)
Select Case sShort
Case "MUS2"
sPrintpath = "\\140_T_MUSIC\MUSICPRINT"
Case "TEX_"
sPrintpath = "\\support\textiles"
Case "SEN0"
sPrintPath = "\\support\116"
Case "117A"
sPrintPath = "\\support\Laserjet 117B"
Case "117B"
sPrintPath = "\\support\Laserjet 117C"
Case "STR_"
sPrintPath = "\\support\Staffroom"
Case "129_"
sPrintPath = "\\support\Brother HL-1440 -129-"
Case "204A"
sPrintPath = "\\support\LaserJet -204A-"
Case "204B"
sPrintPath = "\\support\Laserjet -204B-"
Case "204C"
sPrintPath = "\\support\LaserJet -204C-"
Case "64_A"
sPrintPath = "\\support\Laserjet -64A-"
Case "64_B"
sPrintPath = "\\support\Laserjet -64B-"
Case "65_A"
sPrintPath = "\\support\Brother65"
Case "KB4A"
sPrintPath = "\\support\K4A"
Case "KB4B"
sPrintPath = "\\support\K4B"
Case "LLRC"
sPrintPath = "\\support\LLRC"
Case "ART2"
sPrintPath = "\\support\ART1"
Case "M1_T"
sPrintPath = "\\support\MFL"
Case "M2_T"
sPrintPath = "\\support\MFL"
Case "M3_T"
sPrintPath = "\\support\MFL"
Case "ENG_"
sPrintPath = "\\support\English"
Case "SCLT"
sPrintPath = "\\support\Science"
Case "FTEC"
sPrintPath = "\\support\FoodTech"
Case "ENG2"
sPrintPath = "\\support\English_2"
Case Else
WScript.Quit
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath
'**************************************************************
'This applies secondary printers(colour) to the user
Select Case sShort
Case "64_A"
sPrintPath = "\\support\A3_64Colour"
Case "64_B"
sPrintPath = "\\support\A3_64Colour"
Case "65_A"
sPrintPath = "\\support\HPcolour - 65"
Case "204A"
sPrintPath = "\\support\204colour"
Case "204B"
sPrintPath = "\\support\204colour"
Case "204C"
sPrintPath = "\\support\204colour"
Case "117A"
sPrintPath = "\\support\117_colour"
Case "117B"
sPrintPath = "\\support\117_colour"
Case "SCLT"
sPrintPath = "\\support\ScienceColour"
Case "KB4A"
sPrintPath = "\\support\K4_COLOUR"
Case "KB4B"
sPrintPath = "\\support\K4_COLOUR"
Case Else
WScript.Quit
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
'**************************************************************
'This applies a third printer to the user
select Case sShort
Case "64_A"
sPrintPath = "\\support\A4_64Colour"
Case "64_B"
sPrintPath = "\\support\A4_64Colour"
Case "65_A"
sPrintPath = "\\support\65_A4_Colour"
Case Else
WScript.Quit
End Select
oNetwork.AddwindowsPrinterConnection sPrintPath