Documentation
¶
Index ¶
- Constants
- Variables
- func AsBool(v any) bool
- func AsBoolSlice(v any) []bool
- func AsFloat32(v any) float32
- func AsFloat32Slice(v any) []float32
- func AsFloat64(v any) float64
- func AsFloat64Slice(v any) []float64
- func AsInt8(v any) int8
- func AsInt8Slice(v any) []int8
- func AsInt16(v any) int16
- func AsInt16Slice(v any) []int16
- func AsInt32(v any) int32
- func AsInt32Slice(v any) []int32
- func AsInt64(v any) int64
- func AsInt64Slice(v any) []int64
- func AsString(v any) string
- func AsStringSlice(v any) []string
- func AsUint8(v any) uint8
- func AsUint8Slice(v any) []uint8
- func AsUint16(v any) uint16
- func AsUint16Slice(v any) []uint16
- func AsUint32(v any) uint32
- func AsUint32Slice(v any) []uint32
- func AsUint64(v any) uint64
- func AsUint64Slice(v any) []uint64
- func ObjectPath(class string, keys map[string]any) string
- func ParseDMTF(s string) (time.Time, error)
- func ParseDMTFInterval(s string) (time.Duration, error)
- func Ptr[T any](v T) *T
- func QuoteWQL(s string) string
- func WQLValue(v any) string
- func Where(expr string, args ...any) string
- type JobError
- type PathRef
- type Row
Constants ¶
const ( // ReturnCompleted: the method finished synchronously with no error. ReturnCompleted uint32 = 0 // ReturnJobStarted: the method started a job — poll the returned // CIM_ConcreteJob reference to a terminal state (WaitJob does this). ReturnJobStarted uint32 = 4096 )
Standard CIM method return codes for asynchronous methods (the (ReturnValue, Job) contract of CIM_ConcreteJob providers such as Hyper-V).
const ( JobStateCompleted int64 = 7 JobStateTerminated int64 = 8 JobStateKilled int64 = 9 JobStateException int64 = 10 // JobStateCompletedWithWarnings is Hyper-V's Msvm_ConcreteJob extension — // terminal and successful. JobStateCompletedWithWarnings int64 = 32768 )
CIM_ConcreteJob.JobState terminal values.
Variables ¶
var ErrInvalidDMTF = errors.New("invalid DMTF datetime")
ErrInvalidDMTF is returned (wrapped) for strings that are not valid DMTF datetime values.
var ErrNotFound = errors.New("wmi: instance not found")
ErrNotFound reports that no instance matched — returned by GetInstance and the generated Get<Class> key lookups.
Functions ¶
func AsBoolSlice ¶
func AsFloat32Slice ¶
func AsFloat64Slice ¶
func AsInt8Slice ¶
func AsInt16Slice ¶
func AsInt32Slice ¶
func AsInt64Slice ¶
func AsStringSlice ¶
func AsUint8Slice ¶
func AsUint16Slice ¶
func AsUint32Slice ¶
func AsUint64 ¶
AsUint64 returns v as a uint64 (parsing strings — WMI's shape for CIM uint64 properties such as disk sizes).
func AsUint64Slice ¶
func ObjectPath ¶ added in v1.0.0
ObjectPath renders a key-qualified relative object path for GetInstance, ExecMethod, and the generated method wrappers:
wmi.ObjectPath("Msvm_ComputerSystem", map[string]any{"Name": id})
// Msvm_ComputerSystem.Name="..."
Keys are emitted sorted (deterministic); string values are double-quoted with \ and " backslash-escaped (WMI path syntax), booleans render as TRUE/FALSE, integers in decimal. No keys renders the singleton form "Class=@".
func ParseDMTF ¶
ParseDMTF parses a DMTF timestamp such as "20260714120000.000000+060" into a time.Time in the fixed zone the offset records. Wildcarded microseconds ("******", produced by some providers) are treated as zero. Interval values (":" separator) are rejected — use ParseDMTFInterval.
func ParseDMTFInterval ¶
ParseDMTFInterval parses a DMTF interval such as "00000001020304.000000:000" (1 day, 2 hours, 3 minutes, 4 seconds) into a time.Duration.
func Ptr ¶ added in v1.0.0
func Ptr[T any](v T) *T
Ptr returns a pointer to v — shorthand for the generated method wrappers' optional scalar in-parameters, e.g. wmi.Ptr(uint16(3)). A nil parameter is omitted from the call; a non-nil one is always sent, including zero values.
func QuoteWQL ¶
QuoteWQL renders s as a single-quoted WQL string literal, escaping backslashes and quotes (WQL escapes with backslash).
func WQLValue ¶
WQLValue renders a Go scalar as a WQL literal: strings quoted via QuoteWQL, booleans as TRUE/FALSE, numbers in decimal, nil as NULL. It works on the reflected kind, so named types with scalar underlying types — the generated enum types — render the same way. Used by the generated Get<Class> key lookups and by Where.
func Where ¶ added in v1.0.0
Where renders a WHERE clause body, substituting each ? with the WQL literal of the corresponding arg (via WQLValue, so strings are quoted and escaped):
v2.QueryMsvmComputerSystem(svc, wmi.Where("Name = ?", id))
Every value should arrive through an arg — a literal ? elsewhere in expr is substituted too. Count mismatches are programming errors and stay visible: surplus ?s are left as-is, surplus args are ignored.
Types ¶
type JobError ¶ added in v1.0.0
type JobError struct {
// What is the qualified method name, e.g. "Msvm_ComputerSystem.RequestStateChange".
What string
// ReturnValue is the method's raw return code.
ReturnValue uint32
// JobPath, JobState, ErrorCode, and Description are filled when a started
// job failed (JobState is then terminal and non-successful).
JobPath string
JobState int64
ErrorCode int64
Description string
}
JobError is a failed CIM method call or job: a non-zero, non-job-started ReturnValue, or a started job that reached a failing terminal state.
type PathRef ¶ added in v1.0.0
type PathRef struct {
// Server and Namespace are set for absolute paths
// (\\server\root\cimv2:...); empty for relative paths.
Server string
Namespace string
Class string
// Keys maps key property name to its unescaped value ("Spooler" for
// Name="Spooler", "0" for Index=0). Empty for class and singleton paths.
Keys map[string]string
// Singleton reports the Class=@ form.
Singleton bool
}
PathRef is a parsed WMI object path.
func ParsePath ¶ added in v1.0.0
ParsePath splits a __PATH or __RELPATH into its parts — the structured counterpart of the strings the runtime and generated wrappers pass around:
ref, _ := wmi.ParsePath(`\\HOST\root\virtualization\v2:Msvm_ComputerSystem.Name="4764334d-..."`) ref.Keys["Name"] // "4764334d-..."
Handles the optional \\server\namespace: prefix, a bare namespace: prefix, quoted key values with \" and \\ escapes, and the singleton form Class=@.
type Row ¶
Row is one WMI instance: property name → decoded Go value. Scalars widen to string, int64, uint64, bool, or float64; array properties decode to typed slices of those; embedded CIM objects decode to a nested Row (its __CLASS system property names the embedded class); NULL properties are nil.
func AsRow ¶
AsRow returns v as a Row (embedded CIM objects decode to nested Rows); nil for anything else.
func AsRowSlice ¶
func Instance ¶
Instance builds a Row describing an embedded CIM object for a method in-parameter, e.g.
wmi.Instance("Win32_ProcessStartup", map[string]any{"ShowWindow": uint16(0)})
The __CLASS key tells the runtime which class to spawn; rows returned by queries already carry it.
func ParseObjectText ¶ added in v1.0.0
ParseObjectText parses CIM DTD 2.0 XML embedded-instance text into a Row — the inverse of Service.ObjectText. Some providers return embedded instances as serialized strings (notably Hyper-V's Msvm_KvpExchangeComponent.GuestIntrinsicExchangeItems); this decodes them with typed values instead of hand-parsing the XML. Pure Go: Windows declines to implement the COM inverse (IWbemObjectTextSrc::CreateFromText → WBEM_E_METHOD_NOT_IMPLEMENTED).
Values are typed by each property's TYPE attribute using the Row conventions (integers to int64, uint64 to uint64, real to float64, boolean to bool, everything else string); array properties become typed slices; embedded VALUE.OBJECT instances become nested Rows; properties without a VALUE are nil.