mi

package
v0.30.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Rendered for windows/amd64

Overview

mi is a package that provides a Go API for Windows Management Infrastructure (MI) functions. It requires Windows Management Framework 3.0 or later.

https://learn.microsoft.com/de-de/previous-versions/windows/desktop/wmi_v2/why-use-mi-

Index

Constants

View Source
const (
	LocaleEnglish = "en-us"
)

Variables

View Source
var (
	// DestinationOptionsTimeout is the key for the timeout option.
	//
	// https://github.com/microsoft/win32metadata/blob/527806d20d83d3abd43d16cd3fa8795d8deba343/generation/WinSDK/RecompiledIdlHeaders/um/mi.h#L7830
	DestinationOptionsTimeout = UTF16PtrFromString[*uint16]("__MI_DESTINATIONOPTIONS_TIMEOUT")

	// DestinationOptionsUILocale is the key for the UI locale option.
	//
	// https://github.com/microsoft/win32metadata/blob/527806d20d83d3abd43d16cd3fa8795d8deba343/generation/WinSDK/RecompiledIdlHeaders/um/mi.h#L8248
	DestinationOptionsUILocale = UTF16PtrFromString[*uint16]("__MI_DESTINATIONOPTIONS_UI_LOCALE")
)
View Source
var (
	ErrNotInitialized    = errors.New("not initialized")
	ErrInvalidEntityType = errors.New("invalid entity type")
)
View Source
var (
	NamespaceRootCIMv2             = utils.Must(NewNamespace("root/CIMv2"))
	NamespaceRootWindowsFSRM       = utils.Must(NewNamespace("root/microsoft/windows/fsrm"))
	NamespaceRootWebAdministration = utils.Must(NewNamespace("root/WebAdministration"))
	NamespaceRootMSCluster         = utils.Must(NewNamespace("root/MSCluster"))
)
View Source
var OperationOptionsTimeout = UTF16PtrFromString[*uint16]("__MI_OPERATIONOPTIONS_TIMEOUT")

OperationOptionsTimeout is the key for the timeout option.

https://github.com/microsoft/win32metadata/blob/527806d20d83d3abd43d16cd3fa8795d8deba343/generation/WinSDK/RecompiledIdlHeaders/um/mi.h#L9240

View Source
var QueryDialectWQL = utils.Must(NewQueryDialect("WQL"))

Functions

func Instance_Print

func Instance_Print(instance *Instance) (string, error)

func UTF16PtrFromString

func UTF16PtrFromString[T *uint16](s string) T

UTF16PtrFromString converts a string to a UTF-16 pointer at initialization time.

Types

type Application

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

Application represents the MI application. https://learn.microsoft.com/de-de/windows/win32/api/mi/ns-mi-mi_application

func Application_Initialize

func Application_Initialize() (*Application, error)

Application_Initialize initializes the MI Application. It is recommended to have only one Application per process.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_application_initializev1

func (*Application) Close

func (application *Application) Close() error

Close deinitializes the management infrastructure client API that was initialized through a call to Application_Initialize.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_application_close

func (*Application) NewDestinationOptions

func (application *Application) NewDestinationOptions() (*DestinationOptions, error)

NewDestinationOptions creates an DestinationOptions object that can be used with the Application.NewSession function.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_application_newdestinationoptions

func (*Application) NewOperationOptions

func (application *Application) NewOperationOptions() (*OperationOptions, error)

NewOperationOptions creates an OperationOptions object that can be used with the operation functions on the Session object.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_application_newoperationoptions

func (*Application) NewSession

func (application *Application) NewSession(options *DestinationOptions) (*Session, error)

NewSession creates a session used to share connections for a set of operations to a single destination.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_application_newsession

type ApplicationFT

type ApplicationFT struct {
	Close                          uintptr
	NewSession                     uintptr
	NewHostedProvider              uintptr
	NewInstance                    uintptr
	NewDestinationOptions          uintptr
	NewOperationOptions            uintptr
	NewSubscriptionDeliveryOptions uintptr
	NewSerializer                  uintptr
	NewDeserializer                uintptr
	NewInstanceFromClass           uintptr
	NewClass                       uintptr
}

ApplicationFT represents the function table of the MI application. https://learn.microsoft.com/de-de/windows/win32/api/mi/ns-mi-mi_applicationft

type Boolean

type Boolean uint8
const (
	False Boolean = 0
	True  Boolean = 1
)

type ClassDecl

type ClassDecl struct {
	Flags          uint32
	Code           uint32
	Name           *uint16
	Mqualifiers    uintptr
	NumQualifiers  uint32
	Mproperties    uintptr
	NumProperties  uint32
	Size           uint32
	SuperClass     *uint16
	SuperClassDecl uintptr
	Methods        uintptr
	NumMethods     uint32

	Schema      uintptr
	ProviderFT  uintptr
	OwningClass uintptr
}

func (*ClassDecl) Properties

func (c *ClassDecl) Properties() []*PropertyDecl

type Datetime

type Datetime struct {
	IsTimestamp bool
	Timestamp   *Timestamp // Used when IsTimestamp is true
	Interval    *Interval  // Used when IsTimestamp is false
}

type DestinationOptions

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

func (*DestinationOptions) Delete

func (do *DestinationOptions) Delete() error

func (*DestinationOptions) SetLocale

func (do *DestinationOptions) SetLocale(locale string) error

SetLocale sets the locale for the destination options.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_destinationoptions_setuilocale

func (*DestinationOptions) SetTimeout

func (do *DestinationOptions) SetTimeout(timeout time.Duration) error

SetTimeout sets the timeout for the destination options.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_destinationoptions_settimeout

type DestinationOptionsFT

type DestinationOptionsFT struct {
	Delete                   uintptr
	SetString                uintptr
	SetNumber                uintptr
	AddCredentials           uintptr
	GetString                uintptr
	GetNumber                uintptr
	GetOptionCount           uintptr
	GetOptionAt              uintptr
	GetOption                uintptr
	GetCredentialsCount      uintptr
	GetCredentialsAt         uintptr
	GetCredentialsPasswordAt uintptr
	Clone                    uintptr
	SetInterval              uintptr
	GetInterval              uintptr
}

type Element

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

func (*Element) GetValue

func (e *Element) GetValue() (any, error)

type Instance

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

func (*Instance) Delete

func (instance *Instance) Delete() error

func (*Instance) GetClassName

func (instance *Instance) GetClassName() (string, error)

func (*Instance) GetElement

func (instance *Instance) GetElement(elementName string) (*Element, error)

func (*Instance) GetElementCount

func (instance *Instance) GetElementCount() (uint32, error)

type InstanceFT

type InstanceFT struct {
	Clone           uintptr
	Destruct        uintptr
	Delete          uintptr
	IsA             uintptr
	GetClassName    uintptr
	SetNameSpace    uintptr
	GetNameSpace    uintptr
	GetElementCount uintptr
	AddElement      uintptr
	SetElement      uintptr
	SetElementAt    uintptr
	GetElement      uintptr
	GetElementAt    uintptr
	ClearElement    uintptr
	ClearElementAt  uintptr
	GetServerName   uintptr
	SetServerName   uintptr
	GetClass        uintptr
}

type Interval

type Interval struct {
	Days         uint32
	Hours        uint32
	Minutes      uint32
	Seconds      uint32
	Microseconds uint32
	Padding1     uint32
	Padding2     uint32
	Padding3     uint32
}

func NewInterval

func NewInterval(interval time.Duration) *Interval

type Namespace

type Namespace *uint16

func NewNamespace

func NewNamespace(namespace string) (Namespace, error)

type Operation

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

Operation represents an operation. https://learn.microsoft.com/en-us/windows/win32/api/mi/ns-mi-mi_operation

func (*Operation) Cancel

func (o *Operation) Cancel() error

func (*Operation) Close

func (o *Operation) Close() error

Close closes an operation handle.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_operation_close

func (*Operation) GetInstance

func (o *Operation) GetInstance() (*Instance, bool, error)

func (*Operation) Unmarshal

func (o *Operation) Unmarshal(dst any) error

type OperationCallbacks

type OperationCallbacks[T any] struct {
	CallbackContext         *T
	PromptUser              uintptr
	WriteError              uintptr
	WriteMessage            uintptr
	WriteProgress           uintptr
	InstanceResult          uintptr
	IndicationResult        uintptr
	ClassResult             uintptr
	StreamedParameterResult uintptr
}

func NewUnmarshalOperationsCallbacks

func NewUnmarshalOperationsCallbacks(dst any, errCh chan<- error) (*OperationCallbacks[OperationUnmarshalCallbacks], error)

type OperationFT

type OperationFT struct {
	Close         uintptr
	Cancel        uintptr
	GetSession    uintptr
	GetInstance   uintptr
	GetIndication uintptr
	GetClass      uintptr
}

OperationFT represents the function table for Operation. https://learn.microsoft.com/en-us/windows/win32/api/mi/ns-mi-mi_operationft

type OperationFlags

type OperationFlags uint32

OperationFlags represents the flags for an operation.

https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wmi_v2/mi-flags

const (
	OperationFlagsDefaultRTTI  OperationFlags = 0x0000
	OperationFlagsBasicRTTI    OperationFlags = 0x0002
	OperationFlagsNoRTTI       OperationFlags = 0x0400
	OperationFlagsStandardRTTI OperationFlags = 0x0800
	OperationFlagsFullRTTI     OperationFlags = 0x0004
)

type OperationOptions

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

func (*OperationOptions) Delete

func (o *OperationOptions) Delete() error

func (*OperationOptions) SetTimeout

func (o *OperationOptions) SetTimeout(timeout time.Duration) error

type OperationOptionsFT

type OperationOptionsFT struct {
	Delete             uintptr
	SetString          uintptr
	SetNumber          uintptr
	SetCustomOption    uintptr
	GetString          uintptr
	GetNumber          uintptr
	GetOptionCount     uintptr
	GetOptionAt        uintptr
	GetOption          uintptr
	GetEnabledChannels uintptr
	Clone              uintptr
	SetInterval        uintptr
	GetInterval        uintptr
}

type OperationUnmarshalCallbacks

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

func (*OperationUnmarshalCallbacks) InstanceResult

func (o *OperationUnmarshalCallbacks) InstanceResult(
	_ *Operation,
	instance *Instance,
	moreResults Boolean,
	instanceResult ResultError,
	errorMessageUTF16 *uint16,
	_ *Instance,
) uintptr

type PropertyDecl

type PropertyDecl struct {
	Flags         uint32
	Code          uint32
	Name          *uint16
	Mqualifiers   uintptr
	NumQualifiers uint32
	PropertyType  ValueType
	ClassName     *uint16
	Subscript     uint32
	Offset        uint32
	Origin        *uint16
	Propagator    *uint16
	Value         uintptr
}

type Query

type Query *uint16

func NewQuery

func NewQuery(query string) (Query, error)

type QueryDialect

type QueryDialect *uint16

func NewQueryDialect

func NewQueryDialect(queryDialect string) (QueryDialect, error)

type ResultError

type ResultError uint32
const (
	MI_RESULT_OK ResultError = iota
	MI_RESULT_FAILED
	MI_RESULT_ACCESS_DENIED
	MI_RESULT_INVALID_NAMESPACE
	MI_RESULT_INVALID_PARAMETER
	MI_RESULT_INVALID_CLASS
	MI_RESULT_NOT_FOUND
	MI_RESULT_NOT_SUPPORTED
	MI_RESULT_CLASS_HAS_CHILDREN
	MI_RESULT_CLASS_HAS_INSTANCES
	MI_RESULT_INVALID_SUPERCLASS
	MI_RESULT_ALREADY_EXISTS
	MI_RESULT_NO_SUCH_PROPERTY
	MI_RESULT_TYPE_MISMATCH
	MI_RESULT_QUERY_LANGUAGE_NOT_SUPPORTED
	MI_RESULT_INVALID_QUERY
	MI_RESULT_METHOD_NOT_AVAILABLE
	MI_RESULT_METHOD_NOT_FOUND
	MI_RESULT_NAMESPACE_NOT_EMPTY
	MI_RESULT_INVALID_ENUMERATION_CONTEXT
	MI_RESULT_INVALID_OPERATION_TIMEOUT
	MI_RESULT_PULL_HAS_BEEN_ABANDONED
	MI_RESULT_PULL_CANNOT_BE_ABANDONED
	MI_RESULT_FILTERED_ENUMERATION_NOT_SUPPORTED
	MI_RESULT_CONTINUATION_ON_ERROR_NOT_SUPPORTED
	MI_RESULT_SERVER_LIMITS_EXCEEDED
	MI_RESULT_SERVER_IS_SHUTTING_DOWN
)

func (ResultError) Error

func (r ResultError) Error() string

func (ResultError) String

func (r ResultError) String() string

type Session

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

Session represents a session.

https://learn.microsoft.com/en-us/windows/win32/api/mi/ns-mi-mi_session

func (*Session) Close

func (s *Session) Close() error

Close closes a session and releases all associated memory.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_session_close

func (*Session) GetApplication

func (s *Session) GetApplication() (*Application, error)

GetApplication gets the Application handle that was used to create the specified session.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_session_getapplication

func (*Session) Query

func (s *Session) Query(dst any, namespaceName Namespace, queryExpression Query) error

Query queries for a set of instances based on a query expression.

func (*Session) QueryInstances

func (s *Session) QueryInstances(flags OperationFlags, operationOptions *OperationOptions, namespaceName Namespace,
	queryDialect QueryDialect, queryExpression string,
) (*Operation, error)

QueryInstances queries for a set of instances based on a query expression.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_session_queryinstances

func (*Session) QueryUnmarshal

func (s *Session) QueryUnmarshal(dst any,
	flags OperationFlags, operationOptions *OperationOptions,
	namespaceName Namespace, queryDialect QueryDialect, queryExpression Query,
) error

QueryUnmarshal queries for a set of instances based on a query expression.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_session_queryinstances

func (*Session) TestConnection

func (s *Session) TestConnection() error

TestConnection queries instances. It is used to test the connection. The function returns an operation that can be used to retrieve the result with Operation.GetInstance. The operation must be closed with Operation.Close. The instance returned by Operation.GetInstance is always nil.

https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_session_testconnection

type SessionFT

type SessionFT struct {
	Close               uintptr
	GetApplication      uintptr
	GetInstance         uintptr
	ModifyInstance      uintptr
	CreateInstance      uintptr
	DeleteInstance      uintptr
	Invoke              uintptr
	EnumerateInstances  uintptr
	QueryInstances      uintptr
	AssociatorInstances uintptr
	ReferenceInstances  uintptr
	Subscribe           uintptr
	GetClass            uintptr
	EnumerateClasses    uintptr
	TestConnection      uintptr
}

SessionFT represents the function table for Session.

https://learn.microsoft.com/en-us/windows/win32/api/mi/ns-mi-mi_session

type Timestamp

type Timestamp struct {
	Year         uint32
	Month        uint32
	Day          uint32
	Hour         uint32
	Minute       uint32
	Second       uint32
	Microseconds uint32
	UTC          int32
}

type ValueType

type ValueType int
const (
	ValueTypeBOOLEAN ValueType = iota
	ValueTypeUINT8
	ValueTypeSINT8
	ValueTypeUINT16
	ValueTypeSINT16
	ValueTypeUINT32
	ValueTypeSINT32
	ValueTypeUINT64
	ValueTypeSINT64
	ValueTypeREAL32
	ValueTypeREAL64
	ValueTypeCHAR16
	ValueTypeDATETIME
	ValueTypeSTRING
	ValueTypeREFERENCE
	ValueTypeINSTANCE
	ValueTypeBOOLEANA
	ValueTypeUINT8A
	ValueTypeSINT8A
	ValueTypeUINT16A
	ValueTypeSINT16A
	ValueTypeUINT32A
	ValueTypeSINT32A
	ValueTypeUINT64A
	ValueTypeSINT64A
	ValueTypeREAL32A
	ValueTypeREAL64A
	ValueTypeCHAR16A
	ValueTypeDATETIMEA
	ValueTypeSTRINGA
	ValueTypeREFERENCEA
	ValueTypeINSTANCEA
	ValueTypeARRAY ValueType = 16
)

Jump to

Keyboard shortcuts

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