I was troubleshooting some vbscript designed to query the default printer of a remote computer when I discovered the error in the script was actually because WMI is returning conflicting or even erroneous information. Please see this screenshot:
Both are against the same computer (CLIFGRIFFIN-PC). The left one is run from a Windows Server 2003 install. The right one is run on the PC itself.
The left one, in addition to having fewer results, also shows that NONE of the printers are default. Which is what is causing the scripting error that led me to investigate this.
Any ideas? It's just bizarre.
EDIT: Here is the code I'm using...
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Dim strComputer
strComputer = WshShell.ExpandEnvironmentStrings("%CLIENTNAME%")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer Where Default = True")
For Each Printer in colInstalledPrinters
For i = 0 to OPrinters.Count - 1 Step 2
If InStr(objPrinters.Item(i+1), Printer.Name) > 0 Then
WshNetwork.SetDefaultPrinter(objPrinters.Item(i+1))
Exit For
End If
Next
Next