HighTechTalks DotNet Forums  

Setting Win32_Printer attributes

Dotnet Framework (WMI) microsoft.public.dotnet.framework.wmi


Discuss Setting Win32_Printer attributes in the Dotnet Framework (WMI) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stephany Young
 
Posts: n/a

Default Setting Win32_Printer attributes - 12-03-2007 , 06:01 PM






Just a bit of background:

I have some machines that, occassionly, lose contact with their default
printer
and, as a result their 'Use Printer Online/Use Printer Offline' setting
becomes
toggled to 'Offline'. The users, of course' are quite merrily 'printing'
away
become perplexed as to why the printer is not printing anything.

I have determined that I can use the WMI Win32_Printer class to ascertain if
a
given printer is considered to be 'Offline' but I can't figure out how to
toggle
the appropriate attribute for a given printer.

The following fragment nicely lists the installed printers along with a note
if a
given printer is 'Offline':

Dim _scope As New ManagementScope("\root\cimv2")

_scope.Connect()

Dim _searcher As New ManagementObjectSearcher("select * from
win32_printer")

For Each _printer As ManagementObject In _searcher.Get()
Console.Write("{0}", _printer("name"))
If Convert.ToBoolean(_printer("workoffline")) Then Console.Write("
(Offline)")
Console.WriteLine()
Next

Obviously, becaue I can determine the name of the default printer, I can
target a
specific printer.

Does anyone have a fragment to share that demonstrates how to go about
setting
the 'workoffline' attribute (or, for that matter, any other attribute of the
Win32_Printer class)?


Reply With Quote
  #2  
Old   
Stephany Young
 
Posts: n/a

Default Re: Setting Win32_Printer attributes - 12-03-2007 , 06:11 PM






Got it!

One has to execute:

object.Put()

following the:

object.SetPropertyValue("workoffline", False)


"Stephany Young" <noone@localhost> wrote

Quote:
Just a bit of background:

I have some machines that, occassionly, lose contact with their default
printer
and, as a result their 'Use Printer Online/Use Printer Offline' setting
becomes
toggled to 'Offline'. The users, of course' are quite merrily 'printing'
away
become perplexed as to why the printer is not printing anything.

I have determined that I can use the WMI Win32_Printer class to ascertain
if a
given printer is considered to be 'Offline' but I can't figure out how to
toggle
the appropriate attribute for a given printer.

The following fragment nicely lists the installed printers along with a
note if a
given printer is 'Offline':

Dim _scope As New ManagementScope("\root\cimv2")

_scope.Connect()

Dim _searcher As New ManagementObjectSearcher("select * from
win32_printer")

For Each _printer As ManagementObject In _searcher.Get()
Console.Write("{0}", _printer("name"))
If Convert.ToBoolean(_printer("workoffline")) Then Console.Write("
(Offline)")
Console.WriteLine()
Next

Obviously, becaue I can determine the name of the default printer, I can
target a
specific printer.

Does anyone have a fragment to share that demonstrates how to go about
setting
the 'workoffline' attribute (or, for that matter, any other attribute of
the
Win32_Printer class)?



Reply With Quote
Reply




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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.