wmi
wmi copied to clipboard
Invalid class when querying Win32_Process
As part of troubleshooting an issue encountered with wmi_exporter, I tried running the provided code example which queries Win32_Process:
package main
import (
"github.com/StackExchange/wmi"
"log"
)
type Win32_Process struct {
Name string
}
func main() {
var dst []Win32_Process
q := wmi.CreateQuery(&dst, "")
err := wmi.Query(q, &dst)
if err != nil {
log.Fatal(err)
}
for i, v := range dst {
println(i, v.Name)
}
}
It fails on an instance of Windows Server 2012 Standard, 64-bit with the following error:
2019/09/05 10:32:37 Exception occurred. (Invalid class )
However the following PowerShell snippet works:
Get-WmiObject -Query "SELECT Name FROM Win32_Process"
The output looks like:
__GENUS : 2
__CLASS : Win32_Process
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Name : System Idle Process
PSComputerName :
...
In addition, if I run
winmgmt /verifyrepository
the result is
WMI repository is consistent
Also, if I run wmimgmt.msc
and open the properties for WMI Control (Local)
, no errors are shown.
Any ideas of how to proceed?
Could you try next:
cmd :=
SELECT * FROM Win32_Process if err := wmi.Query(cmd, &dst ); err != nil{ //... }
As the same, but I got an error message "invalid class when querying Win32_ComputerSystem".