Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


set duplex option for printers using multiple wildcards for printer name

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> set duplex option for printers using multiple wildcards for printer name
  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 >>
 set duplex option for printers using multiple wildcards... - 6/29/2008 12:54:42 PM   
  gunk

 

Posts: 4
Score: 0
Joined: 6/29/2008
Status: offline
I need a script to set duplex printing on all printers matching that match one or more name patterns I specify.

So far I have been able to get close using a simple batch file and setprinter.exe from a Microsoft resource kit:

REM [Set Global Defaults]
setprinter PrinterName 8 "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate"


REM [Set User Defaults]
setprinter PrinterName 2 "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate"

I can also set these settings for all installed printers by replacing PrinterName with "" however it does not appear to support wildcards. What I need is to be able to set these options if the printer name contains "ricoh", "2020", "3030" or "3045".
 
 
Post #: 1
 
 RE: set duplex option for printers using multiple wildc... - 7/7/2008 5:22:35 PM   
  gunk

 

Posts: 4
Score: 0
Joined: 6/29/2008
Status: offline
I have a script now which retrieves all printers with 3045 in the name, this is the bit that does it:

"SELECT * FROM Win32_PrinterConfiguration Where DeviceName Like '%3045%'"

All I need now is to have it retreive printers using multiple wildcards, something along the lines of:

"SELECT * FROM Win32_PrinterConfiguration Where DeviceName Like '%3045%' or '%2020%' or '%3030%' "


Is something like this possible?

(in reply to gunk)
 
 
Post #: 2
 
 RE: set duplex option for printers using multiple wildc... - 7/8/2008 12:25:10 AM   
  dm_4ever


Posts: 2430
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
DeviceName Like 'blah' or  DeviceName Like 'blah2' or  DeviceName Like 'blah3'

_____________________________

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 gunk)
 
 
Post #: 3
 
 RE: set duplex option for printers using multiple wildc... - 7/9/2008 2:51:42 PM   
  gunk

 

Posts: 4
Score: 0
Joined: 6/29/2008
Status: offline
Thanks!

(in reply to dm_4ever)
 
 
Post #: 4
 
 RE: set duplex option for printers using multiple wildc... - 7/10/2008 1:44:10 PM   
  gunk

 

Posts: 4
Score: 0
Joined: 6/29/2008
Status: offline
I've pretty much got this working now. Just one more issue.

I have a script which retrieves all the names of the printers with 3030, 2020 or 3045 in the name. This is it below:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("PHQ-I1101198")
For Each strComputer In arrComputers

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_PrinterConfiguration Where DeviceName like '%5500%' or DeviceName like '%3045%' or DeviceName like '%8150%'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

  For Each objItem In colItems
     WScript.Echo "DeviceName: " & objItem.DeviceName
  Next
Next


This works just fine, but I've tried to use similar code in my final script but it just sets duplex on every printer that is installed:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objShell = CreateObject("WScript.Shell")
strComputer = "PHQ-I1101198"

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_PrinterConfiguration Where DeviceName like '%3030%' or DeviceName like '%3045%' or DeviceName like '%2020%'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

  For Each objItem In colItems
Set printerXYZ = objItem.DeviceName

Set objScriptExec = objShell.Exec("setprinter " & Chr(34) & printerXYZ & Chr(34) & " 8 " & Chr(34) & "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate" & Chr(34))
WScript.Echo objScriptExec.StdOut.ReadAll

Set objScriptExec = objShell.Exec("setprinter " & Chr(34) & printerXYZ & Chr(34) & " 2 " & Chr(34) & "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate" & Chr(34))
WScript.Echo objScriptExec.StdOut.ReadAll
  Next
 
WScript.Echo "Done"

This script is also based on this batch file which usees the setrprinter.exe from microsoft:

REM [Set Global Defaults]
setprinter "printername goes here" 8 "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate"


REM [Set User Defaults]
setprinter "printername goes here" 2 "pdevmode=dmDuplex=2,dmCollate=1,dmFields=|duplex collate"

Can anybody see where I've gone wrong? This is my last day at work and I'd really like to complete my final project.

(in reply to gunk)
 
 
Post #: 5
 
 
 
  

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 >> set duplex option for printers using multiple wildcards for printer name 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