Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Help with printer Script please

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61873
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help with printer Script please
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Help with printer Script please - 6/25/2008 10:39:21 PM   
  robhart84

 

Posts: 4
Score: 0
Joined: 6/25/2008
Status: offline
Hi all,

Im trying to create a script that will delete all printers except for the default and then add some selected printers please see my script below. it almost all works apart from the fact that it deletes the default printer.

Can any one help please?

Thanks in advance


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

I thinks these following 4 lines (not including the blank lines) are where the problem may be

Set colInstalledPrinters =  objWMIService.ExecQuery _                                                
   ("Select * from Win32_Printer Where Default = False")
Set colInstalledPrinters =  objWMIService.ExecQuery
   ("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
   objPrinter.Delete_
Next

Dim oNet
Dim WshShell
DIM WShnetwork
Dim Wsh
' Helper object
Set oNet = CreateObject("WScript.Network")
set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set Wsh = WScript.CreateObject("Wscript.Shell")
on error resume next
'wsh.run "\\fsknightsbridge\ofcscan\autopcc.exe",,True
' Add printer and set as default

oNet.AddWindowsPrinterConnection "\\GTLONDON\Xerox_Colour", "DocuColor 242-252-260 PS"
oNet.AddWindowsPrinterConnection "\\LONDON\KNI_7655_Station_1", "Xerox WorkCentre 7655 rev2"
oNet.AddWindowsPrinterConnection "\\LONDON\KNI_7655_Station_2", "Xerox WorkCentre 7655 rev2"
 
 
Post #: 1
 
 RE: Help with printer Script please - 6/26/2008 12:18:06 AM   
  dm_4ever


Posts: 2666
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you think these two lines are building on each other...they're not....you'll have to combine them into one statement

Set colInstalledPrinters =  objWMIService.ExecQuery _                                                
   ("Select * from Win32_Printer Where Default = False")
Set colInstalledPrinters =  objWMIService.ExecQuery
   ("Select * From Win32_Printer Where Network = True")

I would stick to using Set WshNetwork = CreateObject("WScript.Network")  to add/remove the network printer and WMI to determine which printer is the default.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to robhart84)
 
 
Post #: 2
 
 RE: Help with printer Script please - 6/26/2008 6:08:04 AM   
  robhart84

 

Posts: 4
Score: 0
Joined: 6/25/2008
Status: offline
I played around blindly with the section that i thought was the error and managed to firgure it out

Script as follows

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colInstalledPrinters =  objWMIService.ExecQuery _                                                
  ("Select * from Win32_Printer Where Default = False and Network = True")

For Each objPrinter in colInstalledPrinters
  objPrinter.Delete_
Next

Dim oNet
Dim WshShell
DIM WShnetwork
Dim Wsh
' Helper object
Set oNet = CreateObject("WScript.Network")
set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set Wsh = WScript.CreateObject("Wscript.Shell")
on error resume next
'wsh.run "\\fsknightsbridge\ofcscan\autopcc.exe",,True
' Add printer and set as default

oNet.AddWindowsPrinterConnection "\\GTLONDON\Xerox_Colour", "DocuColor 242-252-260 PS"
oNet.AddWindowsPrinterConnection "\\LONDON\KNI_7655_Station_1", "Xerox WorkCentre 7655 rev2"
oNet.AddWindowsPrinterConnection "\\LONDON\KNI_7655_Station_2", "Xerox WorkCentre 7655 rev2"

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help with printer Script please Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts