Page 1 of 1 1
Topic Options
#138764 - 2005-04-27 01:58 PM Display Default Printer with WMI Question
supermanzdead Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 50
Code:

Function ListDefaultPrinterWMI()
$txtBox.text = ""
For Each $strItem in $lstListView.SelectedItems
$txtBox.appendtext("Listing Default Printer for " + $strItem.text + @CRLF)
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strItem.text + "\root\CIMV2")
If @error = 0
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer")
For Each $strObj in $colItems
If $strObj.Default = "True"
$txtBox.appendtext(" " + $strObj.Name + @CRLF)
EndIf
Next
Else
$txtBox.appendtext(" Error connecting to this workstation via WMI!" + @CRLF)
EndIf
Next
EndFunction



Above is the code I came up with to display the default printer, the only problem is that it wont display networked printers under the person whose logged in's profile if you know what I mean. Can any of you WMI experts help me out?
_________________________
~Mwah

Top
#138765 - 2005-04-27 02:14 PM Re: Display Default Printer with WMI Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
You are impersonating to a remote connection.
Network printers is a user specific setting, with network permissions

you will only get A) network printers that YOU connected while on THAT PC, or B) network printers that the Local System account has, i.e. none

Unless someone has another trick, WMI will not be the way.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#138766 - 2005-04-27 02:40 PM Re: Display Default Printer with WMI Question
supermanzdead Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 50
I am gussing there is a registry key somewhere under HKCU then...but I like WMI!! *cry*
_________________________
~Mwah

Top
#138767 - 2005-04-27 02:52 PM Re: Display Default Printer with WMI Question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Is "gussing" like cussing? Yes there is reg key under HKCU but HKCU is smoke and mirrors so it does not exist remotely.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138768 - 2005-04-27 02:58 PM Re: Display Default Printer with WMI Question
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
hkusers\(sid of remote current user) NOT @sid, as that is you
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#138769 - 2005-04-27 03:04 PM Re: Display Default Printer with WMI Question
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
If we look at -
KiXtart FAQ & How to's

We find:
Default Printer Configuration

This is not as "elegant" as WMI, but gets the job done.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#138770 - 2005-04-27 07:20 PM Re: Display Default Printer with WMI Question
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Here is a UDF to return all the printer connections.

EnumPrinterConnections2() - Enumerates all connected printers

And here is some code to display the current Default Printer

Code:
Break On
Dim $DefPrint
$DefPrint = Split(ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows','Device'),',')[0]
If $DefPrint
? $DefPrint
EndIf




These methods require you to run this and log it during the logon process. Otherwise you would need to remotely load the users profile, or use an @SID method WHILE the remote user is actively logged on.

 

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 339 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.131 seconds in which 0.063 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org