Use WMI to change printer settings like duplex, resolution etc??

M

Mikael Jansson

Hi,
Is it possible to change printer settings (in printer driver on a machine)
with WMI, I found how to read a lot of good stuff with WMI but still have
not found if a way to change settings for a printer on a machine like
duplex, resolution and other stuff thats found if you take printer
preferences on a printer driver.

Please give me some hope, even if its not in WMI is there a way of solving
this in VB.NET and/or VBScript?

have a nice day!

/ Mikael
 
L

Lee Peedin

Mikael,
If you don't mind using an ActiveX dll, I have approx. 95+% of the VB
PrinterObject wrapped in such a dll. All my examples are in ooRexx;
however, it is very easy to use this in VBScript (or any other
scripting language). Wander over to
http://pragmaticlee.safedataisp.net and search the page for
PrinterObject

Lee
 
M

Mikael Jansson

Thanx Lee I will try it and see if it does what I need to do.

I didnt see any documentation on the dll in the zip-file (other than the
..rex example file), do you have any documentation over functions etc ?

/ Mikael
 
L

Lee Peedin

Oops - my bad - I do have a .rtf file of many of the
methods/properties - it's at the office. I'll try to locate it on
Wed. and add it to the zip file.

Of course, if you create your object in VBScript, the only thing you
would have to change in the examples shown is to pass the object the
method/property via object.method vs. object~method.

Lee
 
M

Mikael Jansson

great, looking forward to try it

One other question if you know, is it possible to find the real IPaddress
for a printer that is using a TCP/IP port (not portname)

thanx Lee

/ Mikael
 
?

=?iso-8859-1?q?Markus_M=FCller?=

Hi,
maybe, something like this could help You:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer &
"\root\cimv2")
Set colPorts = objWMIService.ExecQuery ("Select * from
Win32_TCPIPPrinterPort")
For Each objPort in colPorts
wscript.echo objPort.HostAddress
Next

Greetz
 
M

Mikael Jansson

Markus,
I tried this but it returns nothing to me and I have confirmed that I have
at least one printer that is connected to a "standard TCP/IP port".

It really sounds that this will solve my problem but I dont know what I am
doing wrong.

Any good ideas?

cheers

/ Mikael
 
M

Mikael Jansson

Hi again,
I did not solve the problem I had at first completely but I solved why the
script you sent me did not work in my environment. the network printer port
was an "HP Standard TCP/IP port" and not a windows "standard TCP/IP port".
so that must mean that the Win32_TCPIPPrinterPort is only valid for windows
standard TCP/IP ports.

Still I havnt solved how to catch those network printer ports that are
non-windows TCP/IP ports.

/ Mikael
 
G

Gerry Hickman

Mikael said:
was an "HP Standard TCP/IP port" and not a windows "standard TCP/IP port".
so that must mean that the Win32_TCPIPPrinterPort is only valid for windows
standard TCP/IP ports.

Interesting, I wonder if HP provide a "provider".
 
?

=?iso-8859-1?q?Markus_M=FCller?=

Hi Mikael,
maybe You could try to get the necessary data from the registry:
In the key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors
You will find the settings for the installed ports.
Greetz
Markus
 
M

Mikael Jansson

Hi Markus,
aha, look whats hiding in the registry ;-)
That solution is fully enough for me, maybe not the best but working just
fine for my purpose

Thanks for that input Markus!!

/Mikael
 
G

Guest

I'm trying to use your ActiveX dll on an asp page, but it appears the next
error message:

Tipo de error:
RxVB (0x800A01E2)
Printer error
/NETaqua2/ASPprint.asp, line 95

[ line 95: oprn.InitializePrinter() ]. do you know what happens?
thanks
 
L

Lee Peedin

The only time I have seen this error is when there is NO printer
installed on the system you're running it on.

Lee

On Tue, 5 Jul 2005 02:09:03 -0700, Lluís Ma <Lluís
I'm trying to use your ActiveX dll on an asp page, but it appears the next
error message:

Tipo de error:
RxVB (0x800A01E2)
Printer error
/NETaqua2/ASPprint.asp, line 95

[ line 95: oprn.InitializePrinter() ]. do you know what happens?
thanks


Lee Peedin said:
Oops - my bad - I do have a .rtf file of many of the
methods/properties - it's at the office. I'll try to locate it on
Wed. and add it to the zip file.

Of course, if you create your object in VBScript, the only thing you
would have to change in the examples shown is to pass the object the
method/property via object.method vs. object~method.

Lee
 
G

Guest

I've been able to succesfully set options for the printer by using regmon to
find changes in the registry related to the printer. I just turn on regmon
when I am making the change and watch which keys get changed. For example
with my HP LaserJet 4300 dtnsl which has duplex, extra paper tray, and a
stacker/stapler I merge the follwing reg file...

LJ4300.reg ---Sets the device options on the printer. Such as duplex, extra
paper tray,...

****************************************************************

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Print\Printers\HP LaserJet 4300\DsDriver]
"printDuplexSupported"=hex:01
"printStaplingSupported"=hex:01

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Print\Printers\HP LaserJet 4300\PrinterDriverData]
"FeatureKeywordSize"=dword:000001bb
"FeatureKeyword"=hex:45,6e,76,46,65,65,64,65,72,00,4e,6f,74,49,6e,73,74,61,6c,\
6c,65,64,00,0a,54,72,61,79,33,00,54,72,61,79,33,5f,35,30,30,00,0a,54,72,61,\
79,34,00,4e,6f,74,49,6e,73,74,61,6c,6c,65,64,00,0a,41,63,63,65,73,73,6f,72,\
79,4f,75,74,70,75,74,42,69,6e,73,00,35,30,30,53,74,61,70,6c,65,72,00,0a,44,\
75,70,6c,65,78,55,6e,69,74,00,49,6e,73,74,61,6c,6c,65,64,00,0a,4d,65,6d,6f,\
72,79,00,38,30,4d,42,00,0a,50,72,69,6e,74,65,72,48,61,72,64,44,69,73,6b,00,\
4e,6f,74,49,6e,73,74,61,6c,6c,65,64,00,0a,4a,6f,62,52,65,74,65,6e,74,69,6f,\
6e,00,49,6e,73,74,61,6c,6c,65,64,00,0a,44,65,76,69,63,65,49,73,4d,6f,70,69,\
65,72,00,49,6e,73,74,61,6c,6c,65,64,00,0a,48,50,49,6e,73,74,61,6c,6c,61,62,\
6c,65,54,72,61,79,46,65,61,74,75,72,65,4e,61,6d,65,00,45,6e,76,46,65,65,64,\
65,72,00,0a,48,50,49,6e,73,74,61,6c,6c,61,62,6c,65,54,72,61,79,53,69,7a,65,\
00,45,6e,76,46,65,65,64,65,72,2d,31,30,30,2d,45,4e,56,45,4c,4f,50,45,5f,46,\
45,45,44,45,52,00,0a,48,50,49,6e,73,74,61,6c,6c,61,62,6c,65,48,43,4f,00,35,\
30,30,53,74,61,63,6b,65,72,2d,51,32,34,34,32,00,0a,53,63,61,6c,65,46,72,6f,\
6d,4c,61,72,67,65,50,61,70,65,72,00,49,6e,73,74,61,6c,6c,65,64,00,0a,41,63,\
74,75,61,6c,43,75,73,74,6f,6d,52,61,6e,67,65,00,32,31,35,39,30,30,5f,33,35,\
35,36,30,30,00,0a,43,6f,6d,62,69,6e,65,4d,65,64,69,61,54,79,70,65,73,41,6e,\
64,49,6e,70,75,74,42,69,6e,73,00,49,6e,73,74,61,6c,6c,65,64,00,0a,00,00

"TrayFormTable"=hex(7):54,00,72,00,61,00,79,00,20,00,31,00,00,00,4c,00,65,00,\
74,00,74,00,65,00,72,00,00,00,30,00,00,00,54,00,72,00,61,00,79,00,20,00,32,\
00,00,00,4c,00,65,00,74,00,74,00,65,00,72,00,00,00,30,00,00,00,54,00,72,00,\
61,00,79,00,20,00,33,00,20,00,28,00,35,00,30,00,30,00,2d,00,53,00,68,00,65,\
00,65,00,74,00,29,00,00,00,4c,00,65,00,74,00,74,00,65,00,72,00,00,00,30,00,\
00,00,4d,00,61,00,6e,00,75,00,61,00,6c,00,20,00,46,00,65,00,65,00,64,00,20,\
00,28,00,54,00,72,00,61,00,79,00,20,00,31,00,29,00,00,00,4c,00,65,00,74,00,\
74,00,65,00,72,00,00,00,30,00,00,00,00,00


****************************************************************

HTH,
Slacker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top