Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > Windows Script Host
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Printer Script issue on XP

Printer Script issue on XP

this thread has 1 replies and has been viewed 659 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 8th August 2012, 18:52
Richard.broadfield Richard.broadfield is offline
Casual
Casual
 
 Join Date: Aug 2012
  6 month star
 Posts: 1
 Reputation: Richard.broadfield is on a distinguished road (10)
Default Printer Script issue on XP

Hello,

I am having difficulties with the below script.

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

==========================================
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:
' \\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"

'Printer names are \\SERVERNAME\PRINTERNAME **NOT** \\SERVERNAME\SHARENAME
'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

   Next
Loop
==========================================

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 at 21:35.. Reason: [CODE] tags added
  #2  
Old 8th August 2012, 21:38
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,265
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (903)
Default 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
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
printer script mlabs General Scripting 2 21st October 2009 15:37
Printer script bigalusn General Scripting 3 15th April 2009 00:22
VB script to map printer!! Need Help!! ahtshun General Scripting 7 29th August 2008 18:24
Unattended Printer Script anthon General Scripting 12 27th April 2007 22:01
printer+script alitoday Windows Server 2000 / 2003 0 19th January 2005 10:15


All times are GMT +3. The time now is 07:52.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri