wmiext

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	// WMI HRESULT values
	WBEM_S_NO_ERROR     = 0
	WBEM_S_FALSE        = 1
	WBEM_S_NO_MORE_DATA = 0x40005

	// WMI Generic flags
	WBEM_FLAG_RETURN_WBEM_COMPLETE = 0x0
	WBEM_FLAG_RETURN_IMMEDIATELY   = 0x10
	WBEM_FLAG_FORWARD_ONLY         = 0x20

	// WMI Query flags
	WBEM_FLAG_SHALLOW = 1

	// Timeout flags
	WBEM_NO_WAIT  = 0
	WBEM_INFINITE = 0xFFFFFFFF

	// COM Auth Flags
	EOAC_NONE = 0

	// RPC Authentication
	RPC_C_AUTHN_WINNT = 10

	// RPC Authentication Level
	RPC_C_AUTHN_LEVEL_DEFAULT = 0
	RPC_C_AUTHN_LEVEL_CALL    = 3

	// RPC Authorization
	RPC_C_AUTHZ_NONE = 0

	// RPC Impersonation
	RPC_C_IMP_LEVEL_IMPERSONATE = 3
)
View Source
const (
	WBEM_FLAG_CONNECT_USE_MAX_WAIT = 0x80
)
View Source
const (
	WmiPathKey = "__PATH"
)

Variables

View Source
var (
	WindowsEpoch = time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC)
)

Functions

func CoSetProxyBlanket

func CoSetProxyBlanket(service *ole.IUnknown) (err error)

func CreateNumericArrayVariant

func CreateNumericArrayVariant(array interface{}, itemType ole.VT) (ole.VARIANT, error)

func CreateStringArrayVariant

func CreateStringArrayVariant(array []string) (ole.VARIANT, error)

func NewAutomationVariant

func NewAutomationVariant(value interface{}) (ole.VARIANT, error)

NewAutomationVariant returns a new VARIANT com

func NextObject

func NextObject(enum *Enum, target interface{}) (bool, error)

NextObject obtains the next instance in an enumeration and sets all fields of the struct pointer passed through the target parameter. Otherwise, if the target parameter is not a struct pointer type, an error will be returned.

func WaitJob

func WaitJob(service *Service, job *Instance) error

WaitJob waits on the specified job instance until it has completed and returns a JobError containing the result code in the event of a failure.

Types

type CIMTYPE_ENUMERATION

type CIMTYPE_ENUMERATION uint32
const (
	CIM_ILLEGAL    CIMTYPE_ENUMERATION = 0xFFF
	CIM_EMPTY      CIMTYPE_ENUMERATION = 0
	CIM_SINT8      CIMTYPE_ENUMERATION = 16
	CIM_UINT8      CIMTYPE_ENUMERATION = 17
	CIM_SINT16     CIMTYPE_ENUMERATION = 2
	CIM_UINT16     CIMTYPE_ENUMERATION = 18
	CIM_SINT32     CIMTYPE_ENUMERATION = 3
	CIM_UINT32     CIMTYPE_ENUMERATION = 19
	CIM_SINT64     CIMTYPE_ENUMERATION = 20
	CIM_UINT64     CIMTYPE_ENUMERATION = 21
	CIM_REAL32     CIMTYPE_ENUMERATION = 4
	CIM_REAL64     CIMTYPE_ENUMERATION = 5
	CIM_BOOLEAN    CIMTYPE_ENUMERATION = 11
	CIM_STRING     CIMTYPE_ENUMERATION = 8
	CIM_DATETIME   CIMTYPE_ENUMERATION = 101
	CIM_REFERENCE  CIMTYPE_ENUMERATION = 102
	CIM_CHAR16     CIMTYPE_ENUMERATION = 103
	CIM_OBJECT     CIMTYPE_ENUMERATION = 13
	CIM_FLAG_ARRAY CIMTYPE_ENUMERATION = 0x2000
)

type Enum

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

func (*Enum) Close

func (e *Enum) Close()

func (*Enum) Next

func (e *Enum) Next() (instance *Instance, err error)

Next returns the next object instance in this iteration

type IEnumWbemClassObjectVtbl

type IEnumWbemClassObjectVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr
	Reset          uintptr
	Next           uintptr
	NextAsync      uintptr
	Clone          uintptr
	Skip           uintptr
}

type IWbemClassObjectVtbl

type IWbemClassObjectVtbl struct {
	QueryInterface          uintptr
	AddRef                  uintptr
	Release                 uintptr
	GetQualifierSet         uintptr
	Get                     uintptr
	Put                     uintptr
	Delete                  uintptr
	GetNames                uintptr
	BeginEnumeration        uintptr
	Next                    uintptr
	EndEnumeration          uintptr
	GetPropertyQualifierSet uintptr
	Clone                   uintptr
	GetObjectText           uintptr
	SpawnDerivedClass       uintptr
	SpawnInstance           uintptr
	CompareTo               uintptr
	GetPropertyOrigin       uintptr
	InheritsFrom            uintptr
	GetMethod               uintptr
	PutMethod               uintptr
	DeleteMethod            uintptr
	BeginMethodEnumeration  uintptr
	NextMethod              uintptr
	EndMethodEnumeration    uintptr
	GetMethodQualifierSet   uintptr
	GetMethodOrigin         uintptr
}

type IWbemLocatorVtbl

type IWbemLocatorVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr
	ConnectServer  uintptr
}

type IWbemServicesVtbl

type IWbemServicesVtbl struct {
	QueryInterface             uintptr
	AddRef                     uintptr
	Release                    uintptr
	OpenNamespace              uintptr
	CancelAsyncCall            uintptr
	QueryObjectSink            uintptr
	GetObject                  uintptr
	GetObjectAsync             uintptr
	PutClass                   uintptr
	PutClassAsync              uintptr
	DeleteClass                uintptr
	DeleteClassAsync           uintptr
	CreateClassEnum            uintptr
	CreateClassEnumAsync       uintptr
	PutInstance                uintptr
	PutInstanceAsync           uintptr
	DeleteInstance             uintptr
	DeleteInstanceAsync        uintptr
	CreateInstanceEnum         uintptr
	CreateInstanceEnumAsync    uintptr
	ExecQuery                  uintptr
	ExecQueryAsync             uintptr
	ExecNotificationQuery      uintptr
	ExecNotificationQueryAsync uintptr
	ExecMethod                 uintptr
	ExecMethodAsync            uintptr
}

type Instance

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

func (*Instance) BeginEnumeration

func (i *Instance) BeginEnumeration() error

BeginEnumeration begins iterating the property list on this instance. This is an advanced method. In most cases, the GetAsXXX() methods, GetAll(), and GetAllProperties() methods should be preferred.

func (*Instance) BeginInvoke

func (i *Instance) BeginInvoke(method string) *MethodExecutor

BeginInvoke invokes a method on this Instance. Returns a MethodExecutor builder object that is used to construct the input parameters (via calls to In()), perform the invocation (using calls to Execute()), retrieve output parameters (via calls to Out()), and finally the method return value (using a call to End())

func (*Instance) CloneInstance

func (i *Instance) CloneInstance() (*Instance, error)

CloneInstance create a new cloned copy of this WMI instance.

func (*Instance) Close

func (i *Instance) Close()

Close cleans up all memory associated with this instance.

func (*Instance) EndEnumeration

func (i *Instance) EndEnumeration() error

EndEnumeration completes iterating a property list on this instance. This is an advanced method. In most cases, the GetAsXXX() methods, GetAll(), and GetAllProperties() methods should be preferred.

func (*Instance) GetAll

func (i *Instance) GetAll(target interface{}) error

GetAll gets all fields that map to a target struct and populates all struct fields according to the expected type information. The target parameter should be a pointer to a struct, and will return an error otherwise.

func (*Instance) GetAllProperties

func (i *Instance) GetAllProperties() (map[string]interface{}, error)

GetAllProperties gets all properties on this instance. The returned map is keyed by the field name and the value is a Golang type which matches the WMI internal implementation. For static type conversions, it's recommended to use either GetAll(), which uses struct fields for type information, or the GetAsXXX() methods.

func (*Instance) GetAsAny

func (i *Instance) GetAsAny(name string) (interface{}, CIMTYPE_ENUMERATION, WBEM_FLAVOR_TYPE, error)

GetAsAny gets a property and converts it to a Golang type that matches the internal variant automation type passed back from WMI. For usage with predictable static type mapping, use GetAsString(), GetAsUint(), or GetAll() instead of this method.

func (*Instance) GetAsString

func (i *Instance) GetAsString(name string) (value string, err error)

GetAsString gets a property value as a string value, converting if necessary

func (*Instance) GetAsUint

func (i *Instance) GetAsUint(name string) (uint, error)

GetAsUint gets a property value as a uint value, if conversion is possible. Otherwise, returns an error.

func (*Instance) GetAsVariant

func (i *Instance) GetAsVariant(name string) (*ole.VARIANT, CIMTYPE_ENUMERATION, WBEM_FLAVOR_TYPE, error)

GetAsVariant obtains a specified property value, if it exists.

func (*Instance) GetCimText

func (i *Instance) GetCimText() string

GetCimText returns the CIM XML representation of this instance. Some WMI methods use a string parameter to represent a full complex object, and this method is used to generate the expected format.

func (*Instance) GetClassName

func (i *Instance) GetClassName() (className string, err error)

GetClassName Gets the WMI class name for this WMI object instance

func (*Instance) GetMethodParameters

func (i *Instance) GetMethodParameters(method string) (*Instance, error)

GetMethodParameters returns a WMI class object which represents the [in] method parameters for a method invocation. This is an advanced method, used for dynamic introspection or manual method invocation. In most cases it is recommended to use BeginInvoke() instead, which constructs the parameter payload automatically.

func (*Instance) IsReferenceProperty

func (i *Instance) IsReferenceProperty(name string) (bool, error)

IsReferenceProperty returns whether the property is of type CIM_REFERENCE, a string which points to an object path of another instance.

func (*Instance) Next

func (i *Instance) Next() (done bool, name string, value interface{}, cimType CIMTYPE_ENUMERATION, flavor WBEM_FLAVOR_TYPE, err error)

Next retrieves the next property as a Golang type when iterating the properties using an enumerator created by BeginEnumeration(). The returned value's type represents the internal automation type used by WMI. It is usually preferred to use GetAsXXX(), GetAll(), or GetAll Properties() over this method.

func (*Instance) NextAsVariant

func (i *Instance) NextAsVariant() (bool, string, *ole.VARIANT, CIMTYPE_ENUMERATION, WBEM_FLAVOR_TYPE, error)

NextAsVariant retrieves the next property as a VARIANT type when iterating the properties using an enumerator created by BeginEnumeration(). The returned value's type represents the internal automation type used by WMI. It is usually preferred to use GetAsXXX(), GetAll(), or GetAllProperties() over this method. Callers are responsible for clearing the VARIANT, otherwise associated memory will leak.

func (*Instance) Path

func (i *Instance) Path() (string, error)

Path gets the WMI object path of this instance

func (*Instance) Put

func (i *Instance) Put(name string, value interface{}) (err error)

Put sets the specified property to the passed Golang value, converting appropriately.

func (*Instance) PutAll

func (i *Instance) PutAll(src interface{}) error

PutAll sets all fields of this instance to the passed src parameter's fields, converting accordingly. The src parameter must be a pointer to a struct, otherwise an error will be returned.

func (*Instance) SpawnInstance

func (i *Instance) SpawnInstance() (instance *Instance, err error)

SpawnInstance create a new WMI object instance that is zero-initialized. The returned instance will not respect expected default values, which must be populated by other means.

type JobError

type JobError struct {
	ErrorCode int
}

func (*JobError) Error

func (err *JobError) Error() string

type MethodExecutor

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

func (*MethodExecutor) End

func (e *MethodExecutor) End() error

End completes the method invocation and returns an error indicating the return code of the underlying method

func (*MethodExecutor) Error

func (e *MethodExecutor) Error() error

Obtains the last error that occurred while building the invocation. Once an error has occurred, all future operations are treated as a no-op.

func (*MethodExecutor) Execute

func (e *MethodExecutor) Execute() *MethodExecutor

Execute executes the method after in parameters have been specified using In()

func (*MethodExecutor) In

func (e *MethodExecutor) In(name string, value interface{}) *MethodExecutor

In sets an input parameter for the method of this invocation, converting appropriately

func (*MethodExecutor) Out

func (e *MethodExecutor) Out(name string, value interface{}) *MethodExecutor

Out sets the specified output parameter, and assigns the value parameter to the result. The value parameter must be a reference to the field that should be set.

type Service

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

func NewLocalService

func NewLocalService(namespace string) (s *Service, err error)

NewLocalService creates a service and connect it to the local system at the specified namespace

func (*Service) Close

func (s *Service) Close()

Close frees all associated memory with this service

func (*Service) CreateInstance

func (s *Service) CreateInstance(className string, src interface{}) (*Instance, error)

CreateInstance creates a new WMI object class instance of the specified className, and sets all properties according to the passed in struct pointer through the src parameter, converting appropriately.

func (*Service) CreateInstanceEnum

func (s *Service) CreateInstanceEnum(className string) (*Enum, error)

CreateInstanceEnum creates an enumerator that iterates all registered object instances for a given className.

func (*Service) ExecMethod

func (s *Service) ExecMethod(className string, methodName string, inParams *Instance) (*Instance, error)

ExecMethod executes a method using the specified class and parameter payload instance. The parameter payload instance can be constructed using Instance.GetMethodParameters(). This is an advanced method, it is recommended to use BeginInvoke() instead, where possible.

func (*Service) ExecQuery

func (s *Service) ExecQuery(wqlQuery string) (*Enum, error)

ExecQuery executes a WQL query and returns an enumeration to iterate the result set. Queries are executed in a semi-synchronous fashion.

func (*Service) FindFirstInstance

func (s *Service) FindFirstInstance(wql string) (*Instance, error)

FindFirstInstance find and returns the first WMI Instance in the result set for a WSL query.

func (*Service) FindFirstObject

func (s *Service) FindFirstObject(wql string, target interface{}) error

FindFirstObject finds and returns the first WMI Instance in the result set for a WSL query, and populates the specified struct pointer passed in through the target parameter.

func (*Service) FindFirstRelatedInstance

func (s *Service) FindFirstRelatedInstance(objPath string, className string) (*Instance, error)

FindFirstRelatedInstance finds and returns a related associator of the specified WMI object path of the expected className type.

func (*Service) FindFirstRelatedInstanceThrough added in v0.0.2

func (s *Service) FindFirstRelatedInstanceThrough(objPath string, resultClass string, assocClass string) (*Instance, error)

FindFirstRelatedInstanceThrough finds and returns a related associator of the specified WMI object path of the expected className type, and only through the expected association type.

func (*Service) FindFirstRelatedObject added in v0.0.2

func (s *Service) FindFirstRelatedObject(objPath string, className string, target interface{}) error

FindFirstRelatedObject finds and returns a related associator of the specified WMI object path of the expected className type, and populates the passed in struct with its fields

func (*Service) GetClassInstance

func (s *Service) GetClassInstance(obj *Instance) (*Instance, error)

GetClassInstance gets the WMI class instance associated with the specified object instance. This method is used to perform schema queries.

func (*Service) GetObject

func (s *Service) GetObject(objectPath string) (instance *Instance, err error)

GetObject obtains a single WMI class or instance given its path

func (*Service) GetObjectAsObject

func (s *Service) GetObjectAsObject(objPath string, target interface{}) error

GetObjectAsObject gets an object by its path and set all fields of the passed in target to match the instance's properties. Conversion is performed as appropriate.

func (*Service) GetSingletonInstance

func (s *Service) GetSingletonInstance(className string) (*Instance, error)

GetSingletonInstance gets the first WMI instance of the specified object class type. This is a shortcut method for uses where only one instance is expected.

func (*Service) RefetchObject

func (s *Service) RefetchObject(instance *Instance) (*Instance, error)

RefetchObject re-fetches the object and returns a new instance. The original instance will not automatically Close(). Callers of this method will need to manually close the original.

func (*Service) SpawnInstance

func (s *Service) SpawnInstance(className string) (*Instance, error)

SpawnInstance creates a new zeroed WMI instance. This instance will not contain expected values. Those must be retrieved and set separately, or CreateInstance() can be used instead.

type WBEM_FLAVOR_TYPE

type WBEM_FLAVOR_TYPE uint32
const (
	WBEM_FLAVOR_DONT_PROPAGATE                  WBEM_FLAVOR_TYPE = 0
	WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE      WBEM_FLAVOR_TYPE = 0x1
	WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS WBEM_FLAVOR_TYPE = 0x2
	WBEM_FLAVOR_MASK_PROPAGATION                WBEM_FLAVOR_TYPE = 0xf
	WBEM_FLAVOR_OVERRIDABLE                     WBEM_FLAVOR_TYPE = 0
	WBEM_FLAVOR_NOT_OVERRIDABLE                 WBEM_FLAVOR_TYPE = 0x10
	WBEM_FLAVOR_MASK_PERMISSIONS                WBEM_FLAVOR_TYPE = 0x10
	WBEM_FLAVOR_ORIGIN_LOCAL                    WBEM_FLAVOR_TYPE = 0
	WBEM_FLAVOR_ORIGIN_PROPAGATED               WBEM_FLAVOR_TYPE = 0x20
	WBEM_FLAVOR_ORIGIN_SYSTEM                   WBEM_FLAVOR_TYPE = 0x40
	WBEM_FLAVOR_MASK_ORIGIN                     WBEM_FLAVOR_TYPE = 0x60
	WBEM_FLAVOR_NOT_AMENDED                     WBEM_FLAVOR_TYPE = 0
	WBEM_FLAVOR_AMENDED                         WBEM_FLAVOR_TYPE = 0x80
	WBEM_FLAVOR_MASK_AMENDED                    WBEM_FLAVOR_TYPE = 0x80
)

Jump to

Keyboard shortcuts

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