Documentation ¶
Overview ¶
Package wmi provides a WQL interface for WMI on Windows.
Example code to print names of running processes:
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) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = &Client{}
DefaultClient is the default Client and is used by Query, QueryNamespace
var (
ErrInvalidEntityType = errors.New("wmi: invalid entity type")
)
Functions ¶
func CreateQuery ¶
CreateQuery returns a WQL query string that queries all columns of src. where is an optional string that is appended to the query, to be used with WHERE clauses. In such a case, the "WHERE" string should appear at the beginning.
func Query ¶
Query runs the WQL query and appends the values to dst.
dst must have type *[]S or *[]*S, for some struct type S. Fields selected in the query must have the same name in dst. Supported types are all signed and unsigned integers, time.Time, string, bool, or a pointer to one of those. Array types are not supported.
By default, the local machine and default namespace are used. These can be changed using connectServerArgs. See http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
Query is a wrapper around DefaultClient.Query.
func QueryNamespace ¶
QueryNamespace invokes Query with the given namespace on the local machine.
Types ¶
type Client ¶
type Client struct { // NonePtrZero specifies if nil values for fields which aren't pointers // should be returned as the field types zero value. // // Setting this to true allows stucts without pointer fields to be used // without the risk failure should a nil value returned from WMI. NonePtrZero bool // PtrNil specifies if nil values for pointer fields should be returned // as nil. // // Setting this to true will set pointer fields to nil where WMI // returned nil, otherwise the types zero value will be returned. PtrNil bool // AllowMissingFields specifies that struct fields not present in the // query result should not result in an error. // // Setting this to true allows custom queries to be used with full // struct definitions instead of having to define multiple structs. AllowMissingFields bool }
A Client is an WMI query client.
Its zero value (DefaultClient) is a usable client.
func (*Client) Query ¶
Query runs the WQL query and appends the values to dst.
dst must have type *[]S or *[]*S, for some struct type S. Fields selected in the query must have the same name in dst. Supported types are all signed and unsigned integers, time.Time, string, bool, or a pointer to one of those. Array types are not supported.
By default, the local machine and default namespace are used. These can be changed using connectServerArgs. See http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
type ErrFieldMismatch ¶
ErrFieldMismatch is returned when a field is to be loaded into a different type than the one it was stored from, or when a field is missing or unexported in the destination struct. StructType is the type of the struct pointed to by the destination argument.
func (*ErrFieldMismatch) Error ¶
func (e *ErrFieldMismatch) Error() string