Printer Script issue on XP

Home Forums Scripting Windows Script Host Printer Script issue on XP

This topic contains 1 reply, has 2 voices, and was last updated by Rems Rems 7 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #159508

    Hello,

    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:
    ‘ \server1printer1,\server2printer2
    ‘ where \server1printer1 is the printer that shall be replaced,
    ‘ and \server2printer2 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 = “\SERVERNAMENETLOGONPrinterMigrationPrintQueues.txt”

    ‘Printer names are \SERVERNAMEPRINTERNAME **NOT** \SERVERNAMESHARENAME
    ‘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 & “rootcimv2”)
    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_USERSoftwareMicrosoftWindows NTCurrentVersionWindowsDevice”)
    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

    Next
    Loop[/CODE]==========================================

    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.[CODE]’ 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:
    ‘ \server1printer1,\server2printer2
    ‘ where \server1printer1 is the printer that shall be replaced,
    ‘ and \server2printer2 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 = “\SERVERNAMENETLOGONPrinterMigrationPrintQueues.txt”

    ‘Printer names are \SERVERNAMEPRINTERNAME **NOT** \SERVERNAMESHARENAME
    ‘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 & “rootcimv2”)
    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_USERSoftwareMicrosoftWindows NTCurrentVersionWindowsDevice”)
    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

    Next
    Loop[/CODE]==========================================

    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.

    Rems
    Rems
    Moderator
    #228217

    Re: Printer Script issue on XP

    Can you show the full error description please.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.