Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done WMIQUERY: suppress "property_name = "

May
12,845
164
Code:
v:\> wmiquery /a . "select Name,DisplayName from Win32_service where Started='TRUE'" | head /n2
DisplayName = Application Information
Name = Appinfo

I'm not sure whether "DisplayName = " and "Name = " are coming from TCC or from WMI. If they're coming from TCC, can there be an option to suppress them? Can they be suppressed even if they're coming from WMI?
 
They're coming from TCC. If you suppress them, you won't get any output from WMIQUERY -- and if you don't want any output, why are you running the command?
I just want the data; that is, instead of "ProcessId = 1024", I want just "1024".
 
Then why aren't you using @WMI?
Because it's very slow. Here's an example I struggled with today.

Having the names of the running services (~65 of them) in a file (or in an array) getting their ProcessId and DisplayName with two @WMI's in a DO loop takes about 4 seconds. Whereas geting Name, ProcessId, and DisplayName all at once with

Code:
wmiquery /a . "select Name,ProcessId,DisplayName from Win32_service where Started='TRUE'"

takes under 1 second.

I can easily get rid of the newlines (discussed in a thread in "Support") by piping to FFIND /vkme"." (or grep).

But getting rid of the verbosity (like "ProcessId = ") is another story. Piping to Gnu\cut is fine, but to do it with internals I think (hope I'm wrong) I'd have to resort to piping to

Code:
do line in @con: (echo %@word ...)
 
Here's one speed example (another to come). Notice that I'm only timins the DO loop with two @WMIs in it and that I'm doing no output. There are 63 services.

Code:
setlocal

set namefile=%@unique[t:\]

sc query | grep SERVICE_NAME | cut -d" " -f2 > %namefile

timer

do l in @%namefile

    set service_pid=%@wmi[.,"select ProcessId from Win32_Service where Name='%l'"]
    
    set display_name=%@wmi[.,"select DisplayName from Win32_Service where Name='%l'"]
    
    REM echo %@format[5,%service_pid]  %@format[-25,%l]  %display_name
    
enddo

timer off

Code:
v:\> services2.btm
Timer 1 on: 21:07:24
Timer 1 off: 21:07:29  Elapsed: 0:00:04.784
 
Compare that time (previous post) to this one.
Code:
v:\> timer set junk=%@execarray[s,wmiquery /a . "select Name,ProcessId,DisplayName from Win32_service where Started='TRUE'" | ffind /kvme"." | cut -d" " -f3-]
Timer 1 on: 21:10:30
Timer 1 off: 21:10:30  Elapsed: 0:00:00.001

v:\> echo %s[0] / %s[1] / %s[2]
Application Information / Appinfo / 6092

v:\> echo %s[180] / %s[181] / %s[182]
Clipboard User Service_405de / cbdhsvc_405de / 8
 
Does TCC get/release an IWBemServices interface every time WMIQUERY or @WMI is called? If so, do you know if that's any more or less costly than actually performing a query? If the interface is not persistent, do you think there would be much benefit in using a persistent one? Perhaps the user could initialize/release it with a command like WMI /O(pen)|/C(lose).
 
This is probably a fairer time comparison (VBS taking about 2/3 the time) not as outrageous as an earlier comparison. The .BTM and .VBS (at end) produce identical results by very similar means. Here's the output for the first two services.

Code:
v:\> wmitest.btm | head /n 8
Appinfo
7040
Application Information
20191103234423.214486-300
AudioEndpointBuilder
2044
Windows Audio Endpoint Builder
20191103234353.907202-300

I've already used a bit of BTM_speed_trickery (UNSET *) to make the BTM faster by a small (but measurable) amount. Quite possibly, not having to massage WMIQUERY's output to remove the property name and remove blank lines would help more. If there are suggestions for making it even faster, please chime in.

Here's the comparison. I've done each many times; the times are typical.

Code:
v:\> timer /q & wmitest.btm > nul & timer
Timer 1 off: 13:31:33  Elapsed: 0:00:00.725

v:\> timer /q & wmitest.vbs > nul & timer
Timer 1 off: 13:31:58  Elapsed: 0:00:00.547

Here are the scripts. I don't know why (anyone?) but the forum won't let me post the code ("Oops! ...") so here's a pic. The files are zipped and attached.

1572979489205.png
 

Attachments

  • wmitest.zip
    763 bytes · Views: 364
Last edited:
Does TCC get/release an IWBemServices interface every time WMIQUERY or @WMI is called? If so, do you know if that's any more or less costly than actually performing a query? If the interface is not persistent, do you think there would be much benefit in using a persistent one? Perhaps the user could initialize/release it with a command like WMI /O(pen)|/C(lose).

No, TCC doesn't get/release it every time. It does one get the first time.

The time-consuming call isn't IWBemServices, it's the connection to the local/remote server, which has to be done every time (unless you you want to restrict all calls to WMIQUERY & @WMI to the same server).
 
Back
Top