wmi

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobStatusStarted  = 4096
	JobStatusRunning  = 4
	JobStateCompleted = 7
)

WMI job statuses

Variables

View Source
var ErrNotFound = errors.New("Query returned empty set")

ErrNotFound is returned when the query yielded no results

Functions

func PopulateStruct

func PopulateStruct(j *Result, s interface{}) (err error)

PopulateStruct populates the fields of the supplied struct with values received form a Result. Care must be taken when declaring the struct. It must match the types returned by WMI.

func WaitForJob

func WaitForJob(jobPath string) error

WaitForJob will wait for a WMI job to complete

Types

type AndQuery

type AndQuery struct {
	QueryFields
}

AndQuery defines an "AND" conditional query.

func (*AndQuery) AsString

func (w *AndQuery) AsString(partialQuery string) (string, error)

AsString implements the Query interface

type JobState

type JobState struct {
	Name             string
	Description      string
	ElementName      string
	ErrorCode        int32
	ErrorDescription string
	InstanceID       string
	JobRunTimes      int32
	JobState         int32
	JobStatus        string
	JobType          int32
}

JobState represents a WMI job that was run. This type exposes a subset of the information available in CIM_ConcreteJob https://msdn.microsoft.com/en-us/library/cc136808%28v=vs.85%29.aspx

func NewJobState

func NewJobState(path string) (JobState, error)

NewJobState returns a new Jobstate, given a path

type Location

type Location struct {
	// Server represents the server on which this query should be run
	Server string
	// Namespace represents the namespace in which to run the query
	Namespace string
	// Class represents the class against which to run the query
	Class string
	// Params is a map of parameters to filter
	Params map[string]string
}

Location contains the parsed fields of a __PATH

func NewLocation

func NewLocation(path string) (*Location, error)

NewLocation returns a *Location object

func (*Location) GetResult

func (w *Location) GetResult() (*Result, error)

GetResult wil return a Result for this Location

func (*Location) QueryParams

func (w *Location) QueryParams() []Query

QueryParams returns a []Query from the params present in the location string

type OrQuery

type OrQuery struct {
	QueryFields
}

OrQuery defines an "OR" conditional query

func (*OrQuery) AsString

func (w *OrQuery) AsString(partialQuery string) (string, error)

AsString implements the Query interface

type Query

type Query interface {
	AsString(partialQuery string) (string, error)
}

Query is an interface that defines a query type

type QueryFields

type QueryFields struct {
	Key   string
	Value interface{}
	Type  QueryType
}

QueryFields is a helper structure that enables us to build queries

type QueryType

type QueryType string

QueryType holds the condition of the query

var (
	// Equals is the qeual conditional for a query
	Equals QueryType = "="
	// Like is the pattern match conditional of a query
	Like QueryType = " Like "
	// Is comparison for null fields
	Is QueryType = " IS "
)

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result holds the raw WMI result of a query

func NewResult

func NewResult(v *ole.VARIANT) *Result

NewResult wraps an ole.VARINT in a *Result

func NewWMIObject

func NewWMIObject(path string) (*Result, error)

NewWMIObject returns a new *Result from a path

func (*Result) Count

func (r *Result) Count() (int, error)

Count returns the total number of results returned by the query.

func (*Result) Elements

func (r *Result) Elements() ([]*Result, error)

Elements returns an array of WMI results

func (*Result) Error

func (r *Result) Error() error

func (*Result) Get

func (r *Result) Get(method string, params ...interface{}) (*Result, error)

Get will execute a method on the WMI object held in *Result, with the given params

func (*Result) GetProperty

func (r *Result) GetProperty(property string) (*Result, error)

GetProperty will return a *Result holding a given property

func (*Result) GetText

func (r *Result) GetText(i int) (string, error)

GetText returns an XML representation of an object or instance

func (*Result) ItemAtIndex

func (r *Result) ItemAtIndex(i int) (*Result, error)

ItemAtIndex returns the result of the ItemIndex WMI call on a raw WMI result object

func (*Result) Path

func (r *Result) Path() (string, error)

Path returns the Path element of this WMI object

func (*Result) Raw

func (r *Result) Raw() *ole.VARIANT

Raw returns the raw WMI result

func (*Result) Set

func (r *Result) Set(property string, params ...interface{}) error

Set will set the parameters of a property

func (*Result) ToArray

func (r *Result) ToArray() *ole.SafeArrayConversion

ToArray returna a *ole.SafeArrayConversion from the WMI result. This should probably not be exposed directly.

func (*Result) Value

func (r *Result) Value() interface{}

Value returns the value of a result as an interface. It is the job of the caller to cast it to it's proper type

type WMI

type WMI struct {
	Namespace string
	Server    string
	// contains filtered or unexported fields
}

WMI represents a WMI connection object

func NewConnection

func NewConnection(params ...interface{}) (*WMI, error)

NewConnection returns a new *WMI connection, given the parameters

func NewStandardCimV2Connection

func NewStandardCimV2Connection() (w *WMI, err error)

NewStandardCimV2Connection returns a new WMI connection to the Root\StandardCimv2 namespace.

func (*WMI) Close

func (w *WMI) Close()

Close will close the WMI connection and release all resources.

func (*WMI) ExecMethod

func (w *WMI) ExecMethod(params ...interface{}) (*Result, error)

ExecMethod wraps the WMI ExecMethod call and returns a *Result

func (*WMI) Get

func (w *WMI) Get(params ...interface{}) (*Result, error)

Get returns a new *Result, given the params

func (*WMI) GetOne

func (w *WMI) GetOne(resource string, fields []string, qParams []Query) (*Result, error)

GetOne returns the first result from a query response.

func (*WMI) Gwmi

func (w *WMI) Gwmi(resource string, fields []string, qParams []Query) (*Result, error)

Gwmi makes a WMI query and returns a *Result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL