Welcome!

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

SignUp Now!

@WMI not working inside POWERMONITOR

May
13,834
211
I have a script which gives the start times of a few services and processes. It's meant to be called when the monitor is turned on (1) or off (0).

Without POWERMONITOR it works OK.

Code:
v:\> monitoron.btm 0
Monitor OFF:           2024-11-03 16:00:09.352

v:\> monitoron.btm 1
Monitor ON:            2024-11-03 16:00:11.344
AppXSvc started:       2024-11-03 15:56:30.121
WaaSMedicSvc started:  2024-10-31 00:50:43.538
RuntimeBroker started: 2024-11-03 15:56:30.077

@WMI fails when I run the script as POWERMONITOR's command.

Code:
v:\> powermonitor Display forever `v:\monitoron.btm %_powerdisplay`

Monitor ON:            2024-11-03 16:01:24.155
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [12]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=7908"]"
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [15]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=0"]"
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [20]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=5060"]"
 
This is a bit squirrelly. Here's the same instance of TCC I was using in my original post last night; now it's working. I don't know what combination of actions caused it to start working

Code:
v:\> powermonitor Display 1 `v:\monitoron.btm %_powerdisplay`

v:\>
Monitor ON:            2024-11-04 10:04:54.807
AppXSvc started:       2024-11-04 09:49:27.293
WaaSMedicSvc started:  2024-10-31 00:50:43.538
RuntimeBroker started: 2024-11-04 00:53:33.552
RuntimeBroker started: 2024-11-04 10:03:33.317

Here's a brand new instance of TCC; it's not working.

Code:
v:\> powermonitor Display 1 `v:\monitoron.btm %_powerdisplay`

v:\>
Monitor ON:            2024-11-04 10:06:04.270
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [14]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=1692"]"
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [17]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=0"]"
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [22]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=7112"]"
Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) V:\monitoron.btm [22]  Incorrect function.
 "%@wmi[.,"select creationdate from Win32_process where processid=8144"]"
 
Cannot debug this without your monitoron.btm script.
It's attached but it has things in it which you probably don't have. Any @WMI will do.

Code:
v:\> powermonitor Display 1 `echo %@wmi[.,"Select ProcessId from Win32_Process where Name='tcc.exe'"]`

v:\> Error : Failed to create instance of WbemStatusCodeText
TCC: (Sys) Incorrect function.
 "%@wmi[.,"Select ProcessId from Win32_Process where Name='tcc.exe'"]"
 

Attachments

I'm just guessing ... a thread is not COM-initialized. And, if so, maybe it's a timing issue. As I said before, it started working (after failing) somewhat miraculously. And this usually works (I might have seen it fail, not sure).

Code:
v:\> thread powermonitor Display 5 `echo %@wmi[.,"Select ProcessId from Win32_Process where Name='tcc.exe'"]`

v:\> 3216
 
I'm just guessing ... a thread is not COM-initialized.
FWIW, I've been messing with two ancient plugins, WMIQ and @WMIQ (cf. WMIQUERY and @WMI). They generally worked but failed inside POWERMONITOR with the same error as WMIQUERY and @WMI. When I wrapped my plugins in CoInitialize/CoUnitialize they worked in that situation.
 
Back
Top