Documentation ¶
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
- Variables
- func Instance_Print(instance *Instance) (string, error)
- func UTF16PtrFromString[T *uint16](s string) T
- type Application
- func (application *Application) Close() error
- func (application *Application) NewDestinationOptions() (*DestinationOptions, error)
- func (application *Application) NewOperationOptions() (*OperationOptions, error)
- func (application *Application) NewSession(options *DestinationOptions) (*Session, error)
- type ApplicationFT
- type Boolean
- type ClassDecl
- type Datetime
- type DestinationOptions
- type DestinationOptionsFT
- type Element
- type Instance
- type InstanceFT
- type Interval
- type Namespace
- type Operation
- type OperationCallbacks
- type OperationFT
- type OperationFlags
- type OperationOptions
- type OperationOptionsFT
- type OperationUnmarshalCallbacks
- type PropertyDecl
- type Query
- type QueryDialect
- type ResultError
- type Session
- func (s *Session) Close() error
- func (s *Session) GetApplication() (*Application, error)
- func (s *Session) Query(dst any, namespaceName Namespace, queryExpression Query) error
- func (s *Session) QueryInstances(flags OperationFlags, operationOptions *OperationOptions, ...) (*Operation, error)
- func (s *Session) QueryUnmarshal(dst any, flags OperationFlags, operationOptions *OperationOptions, ...) error
- func (s *Session) TestConnection() error
- type SessionFT
- type Timestamp
- type ValueType
Constants ¶
const (
LocaleEnglish = "en-us"
)
Variables ¶
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") )
var ( ErrNotInitialized = errors.New("not initialized") ErrInvalidEntityType = errors.New("invalid entity type") )
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")) )
var OperationOptionsTimeout = UTF16PtrFromString[*uint16]("__MI_OPERATIONOPTIONS_TIMEOUT")
OperationOptionsTimeout is the key for the timeout option.
var QueryDialectWQL = utils.Must(NewQueryDialect("WQL"))
Functions ¶
func Instance_Print ¶
func UTF16PtrFromString ¶
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 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 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 Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func (*Instance) GetClassName ¶
func (*Instance) GetElement ¶
func (*Instance) GetElementCount ¶
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 ¶
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) Close ¶
Close closes an operation handle.
https://learn.microsoft.com/en-us/windows/win32/api/mi/nf-mi-mi_operation_close
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 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 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 ¶
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) 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 ¶
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 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 )