+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, problems with my printer Script, can you cast your eye over it? in Coding and Web Development; I keep get intermittent problems with the script we have been running for a longtime. It's normally flawless but now ...
  1. #1
    Disease's Avatar
    Join Date
    Jan 2006
    Posts
    1,059
    Thank Post
    112
    Thanked 63 Times in 44 Posts
    Rep Power
    54

    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

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    Quote Originally Posted by jinnantonnix View Post
    The underscore is telling the interpreter to append the following line as if it were a continuation, isn't it?
    No. This is one of the wacky bits of method names in chunks of the Windows API; they end with an underscore just to make life difficult :-)

    Is the error reproducible (ie always for 1 user, 1 machine etc??) If so, can you try putting in an "on error resume next" at the beginning of the code and then this:
    Code:
    For Each objPrinter in colInstalledPrinters
        objPrinter.Delete_
        if err.number<>0 then
          wscript.echo objPrinter.name
       end if
    Next
    that will at least tell you which printer is not deleting.

    The 0x80040001 error seems to be pretty non-specific ("something's gone wrong but I don't know what!") but there's some stuff here Code 80041001 - VBScript Error called failed which may help; particularly about clearing out the WBEM repository.

  3. #3


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,210
    Thank Post
    218
    Thanked 812 Times in 694 Posts
    Rep Power
    274
    Code:
    ' killprinters.vbs 
    
    Option Explicit
    Dim objNetwork
    on error resume next
    
    Set objNetwork = CreateObject("WScript.Network") 
    
    objNetwork.RemovePrinterConnection "\\server\lasercol", true, true 
    objNetwork.RemovePrinterConnection "\\server\colourlt", true, true
    not sure if this helps at all but thats my printer removal script

  4. #4
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    935
    Thank Post
    99
    Thanked 107 Times in 95 Posts
    Rep Power
    72
    I use a script that picks up the OU of the computer, so when i move a machine in AD (say from year4 classroom to year 5 classroom) it will change the printer for me.

    my script is better explained here: Printer Script that uses a computers Active Directory OU - Blog.Arcath.Net

SHARE:
+ Post New Thread

Similar Threads

  1. A Printer Script
    By Ric_ in forum Scripts
    Replies: 164
    Last Post: 1st October 2010, 10:11 AM
  2. printer script again (sorry)
    By chrbb in forum Scripts
    Replies: 1
    Last Post: 11th July 2008, 12:27 PM
  3. Replies: 13
    Last Post: 20th February 2008, 04:29 PM
  4. Printer Script
    By faza in forum Scripts
    Replies: 9
    Last Post: 14th September 2007, 08:30 AM
  5. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •