WMIC.exe is a standard part of Windows, a command line interface to the WMI (Windows Management Instrumentation) API. WMI can be used to do just about anything with Windows machines, so it's useful from a KBOX script.

I'm experienced in using WMIC from batch files. But I'm trying WMIC.exe for the first time from a Kscript, and it's not working. Here's a command line that works perfectly when run manually from a Command Prompt as a Windows Administrator-equivalent:
WMIC printer GET name
To redirect the output, I can use either of these successfully:
WMIC /OUTPUT:prt.tmp printer GET name
WMIC printer GET name >prt.tmp
But if I run any of those commands in a Kscript which is Run as Local System, the output is always "No Instance(s) available". It doesn't matter whether I use the "Launch a program" step, or put the command in "Run a batch file" step, the result is the same.

So I'm asking all of you (and KACE tech support): Have you used WMIC successfully in a Kscript? If so, what is the trick? Sande
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity



Here is a similar script that is producing results.

I am also running this as local system.

Maybe the win32_printers behave differently when run as local system.

Have you tried running the script as user logged in to console?

Answered 10/18/2010 by: dchristian
Red Belt

Please log in to comment
It's good to know that the problem is not just WMIC when Run as Local System. BTW, I have the same problem if the WMI calls are from a VBscript: "No Instance(s)".

I suspect the problem is specific to the class I'm trying to query on, Win32_Printer. The WMI documentation for this class says that if you're not a Windows Administrator equivalent, you won't see all the printers. It goes on to say that the privilege needed to see all the printers is LoadDriver, so now I'm trying the WMI call in the VBscript to specifically invoke the LoadDriver (and Security) privileges on the call.

Why am I doing this? Because in all versions of Windows, all local printers can be found in the registry under HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers, so I could just query the registry for these. Under Windows XP only, all non-local printers (known as printer connections) can be found in the registry under HKLM\SYSTEM\CurrentControlSet\Control\Print\Connections, but not so in Windows 7 (and Vista). In the newer operating systems, that key does not exist, but the same information can be found in HKCU\Printers\Connections. Of course, HKCU is undefined when running in any of the system accounts, so it does me no good! I was hoping that WMIC or WMI could give me an HKLM-based list of all printers, so I could test for what I need.

Anyone else have any experience with WMIC or WMI calls from Kscripts?
Answered 10/18/2010 by: snissen
Fourth Degree Green Belt

Please log in to comment

I ran this vbs as an offline Kscript this morning.

I did receive results.

Are you getting the no instance when you run your script on all machines?

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\printers.txt", ForAppending, True)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
objTextFile.Writeline(objPrinter.Name & vbTab & objPrinter.location)
Answered 10/19/2010 by: dchristian
Red Belt

Please log in to comment
Ah, thanks dchristian: your script was very useful. First, it does run correctly, without error messages.

Second, it does correctly enumerate all the local printers, but none of the local printer connections. Maybe the printer connections, though set up as per-machine, do not exist outside the context of a particular user.

Because, when logged in as a standard user, the manually entered command: WMIC printer GET name
lists both the local printers and the printer connections.

However, open a command prompt as a local administrator, and that same command gets only the local printers.

So, it turns out that I am working with a particularly screwy part of the WMI namespace.

Still I wish I could get WMIC.exe to run reliably without the "No Instance(s)" error; I'd hoped to use it a lot in batch file shell scripts.

If anyone else out there is doing anything with WMIC in Kscripts, please reply to this message; maybe we can swap some ideas. Sande
Answered 10/19/2010 by: snissen
Fourth Degree Green Belt

Please log in to comment