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