Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Invalid class when querying Win32_Process #50

Open
kongslund opened this issue Sep 5, 2019 · 2 comments
Open

Invalid class when querying Win32_Process #50

kongslund opened this issue Sep 5, 2019 · 2 comments

Comments

@kongslund
Copy link

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?

@pavelblossom
Copy link

Could you try next:
cmd := SELECT * FROM Win32_Process if err := wmi.Query(cmd, &dst ); err != nil{ //... }

@shaneing
Copy link

As the same, but I got an error message "invalid class when querying Win32_ComputerSystem".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants