No announcement yet.

Printer Script issue on XP

  • Filter
  • Time
  • Show
Clear All
new posts

  • Printer Script issue on XP


    I am having difficulties with the below script.

    It works perfectly on Win7/2008 R2, but i get 800a0046 error on WinXP

    ' Script that changes the user's printer(s) to other(s) printer(s) according to a csv list of printers.
    ' The list of printers should contain comma separated printer pairs, one pair at each line, like this:
    ' \\server1\printer1,\\server2\printer2
    ' where \\server1\printer1 is the printer that shall be replaced,
    ' and \\server2\printer2 is the printer that shall replace the beforementioned printer.
    ' The script can be called from a e.g. the logon script and the script can replace several different printers.
    ' Just add more lines to the list of printers and the script will go through them all.
    ' The script also notes which printer is the default printer and sets the replacing printer as default printer.
    ' Created by Dennis Nyholm 23.7.2008
    'Fill in the filename of the list of printers here:
    strFile = "\\SERVERNAME\NETLOGON\PrinterMigration\PrintQueues.txt"
    'Remove Line27 comment to echo command notification to user
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strFile, ForReading)
    Do Until objTextFile.AtEndOfStream
       strLine = objTextFile.Readline
       arrprt = Split(strLine, ",")
       Sourceprt = arrprt(0)
       Destprt = arrprt(1)
       'Wscript.Echo Sourceprt & " => " & Destprt
       strComputer = "."
       'Set error handling on:
       'On Error Resume Next
       Set objNetwork = CreateObject("Wscript.Network")
       Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
       Set colInstalledPrinters = objWMIService.ExecQuery _
         ("SELECT * FROM Win32_Printer")
       For Each objPrinter in colInstalledPrinters
         'Wscript.Echo "Printer Name: " & objPrinter.Name
         If LCase(objPrinter.Name) = LCase(Sourceprt) Then
           'Wscript.Echo objPrinter.Name & " will be replaced by " & Destprt
           'Install replacing printer:
           objNetwork.AddWindowsPrinterConnection Destprt
           'Check default printer:
           Set WshShell = WScript.CreateObject("WScript.Shell")
           strDefaultPrinter = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
           arrDefaultPrinter = Split(strDefaultPrinter, ",")
           'Check if this is the default printer:
           If LCase(arrDefaultPrinter(0)) = LCase(objPrinter.Name) Then
             'Wscript.Echo "Is default printer"
             'Set the printer as default:
             objNetwork.SetDefaultPrinter Destprt
           End If
           'Remove old printer:
           objNetwork.RemovePrinterConnection Sourceprt
         End If

    Has anyone any idea what would cause this? The user is local admin and makes no difference. Windows firewall disabled.

    I reckon its WMI related but not 100% sure.

    Would appreciate a little help.
    Last edited by Rems; 8th August 2012, 19:35. Reason: [CODE] tags added

  • #2
    Re: Printer Script issue on XP

    Can you show the full error description please.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts