cim

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	// PartitionStyleUnknown indicates an unknown partition table format
	PartitionStyleUnknown = 0
	// PartitionStyleGPT indicates the disk uses GUID Partition Table (GPT) format
	PartitionStyleGPT = 2

	// GPTPartitionTypeBasicData is the GUID for basic data partitions in GPT
	// Used for general purpose storage partitions
	GPTPartitionTypeBasicData = "{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}"
	// GPTPartitionTypeMicrosoftReserved is the GUID for Microsoft Reserved Partition (MSR)
	// Reserved by Windows for system use
	GPTPartitionTypeMicrosoftReserved = "{e3c9e316-0b5c-4db8-817d-f92df00215ae}"

	// ErrorCodeCreatePartitionAccessPathAlreadyInUse is the error code (42002) returned when the driver letter failed to assign after partition created
	ErrorCodeCreatePartitionAccessPathAlreadyInUse = 42002
)
View Source
const (
	SmbMappingStatusOK int32 = iota
	SmbMappingStatusPaused
	SmbMappingStatusDisconnected
	SmbMappingStatusNetworkError
	SmbMappingStatusConnecting
	SmbMappingStatusReconnecting
	SmbMappingStatusUnavailable
)

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/smb/msft-smbmapping

View Source
const (
	WMINamespaceCimV2   = "Root\\CimV2"
	WMINamespaceStorage = "Root\\Microsoft\\Windows\\Storage"
	WMINamespaceSmb     = "Root\\Microsoft\\Windows\\Smb"
)
View Source
const (
	FileSystemUnknown = 0
)

Variables

View Source
var (
	DiskSelectorListForDiskNumberAndLocation = []string{"Number", "Location"}
	DiskSelectorListForPartitionStyle        = []string{"PartitionStyle"}
	DiskSelectorListForPathAndSerialNumber   = []string{"Path", "SerialNumber"}
	DiskSelectorListForIsOffline             = []string{"IsOffline"}
	DiskSelectorListForSize                  = []string{"Size"}
)
View Source
var (
	BIOSSelectorList    = []string{"SerialNumber"}
	ServiceSelectorList = []string{"DisplayName", "State", "StartMode"}
)
View Source
var (
	VolumeSelectorListForFileSystemType = []string{"FileSystemType"}
	VolumeSelectorListForStats          = []string{"UniqueId", "SizeRemaining", "Size"}
	VolumeSelectorListUniqueID          = []string{"UniqueId"}

	PartitionSelectorListObjectID = []string{"ObjectId"}
)
View Source
var (
	ISCSITargetPortalDefaultSelectorList = []string{"TargetPortalAddress", "TargetPortalPortNumber"}
)

Functions

func ConnectISCSITarget

func ConnectISCSITarget(portalAddress string, portalPortNumber uint32, nodeAddress string, authType string, chapUsername *string, chapSecret *string) (int, error)

ConnectISCSITarget establishes a connection to an iSCSI target with optional CHAP authentication credential.

Refer https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitarget-connect for the WMI method definition.

func CreatePartition

func CreatePartition(disk *storage.MSFT_Disk, params ...interface{}) (int, error)

CreatePartition creates a partition on a disk.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/createpartition-msft-disk for the WMI method definition.

func DisconnectISCSITarget

func DisconnectISCSITarget(target *storage.MSFT_iSCSITarget, sessionIdentifier string) (int, error)

DisconnectISCSITarget disconnects the specified session between an iSCSI initiator and an iSCSI target.

Refer https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitarget-disconnect for the WMI method definition.

func FilterForPartitionOnDisk

func FilterForPartitionOnDisk(diskNumber uint32) *query.WmiQueryFilter

FilterForPartitionOnDisk creates a WMI query filter to query a disk by its number.

func FilterForPartitionsOfTypeNormal

func FilterForPartitionsOfTypeNormal() *query.WmiQueryFilter

FilterForPartitionsOfTypeNormal creates a WMI query filter for all non-reserved partitions.

func FindPartitionsByVolume

func FindPartitionsByVolume(volumes []*storage.MSFT_Volume) ([]*storage.MSFT_Partition, error)

FindPartitionsByVolume finds all partitions associated with the given volumes using MSFT_PartitionToVolume association.

WMI association MSFT_PartitionToVolume:

Partition                                                               | Volume
---------                                                               | ------
MSFT_Partition (ObjectId = "{1}\\WIN-8E2EVAQ9QSB\ROOT/Microsoft/Win...) | MSFT_Volume (ObjectId = "{1}\\WIN-8E2EVAQ9QS...

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partitiontovolume for the WMI class definition.

func FindVolumesByPartition

func FindVolumesByPartition(partitions []*storage.MSFT_Partition) ([]*storage.MSFT_Volume, error)

FindVolumesByPartition finds all volumes associated with the given partitions using MSFT_PartitionToVolume association.

WMI association MSFT_PartitionToVolume:

Partition                                                               | Volume
---------                                                               | ------
MSFT_Partition (ObjectId = "{1}\\WIN-8E2EVAQ9QSB\ROOT/Microsoft/Win...) | MSFT_Volume (ObjectId = "{1}\\WIN-8E2EVAQ9QS...

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partitiontovolume for the WMI class definition.

func FlushVolume

func FlushVolume(volume *storage.MSFT_Volume) (int, error)

FlushVolume flushes the cached data in the volume's file system to disk.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-volume-flush for the WMI method definition.

func FormatVolume

func FormatVolume(volume *storage.MSFT_Volume, params ...interface{}) (int, error)

FormatVolume formats the specified volume.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/format-msft-volume for the WMI method definition.

func GetBIOSSerialNumber

func GetBIOSSerialNumber(bios *cimv2.CIM_BIOSElement) (string, error)

GetBIOSSerialNumber returns the BIOS serial number.

func GetDiskLocation

func GetDiskLocation(disk *storage.MSFT_Disk) (string, error)

GetDiskLocation returns the location of a disk.

func GetDiskNumber

func GetDiskNumber(disk *storage.MSFT_Disk) (uint32, error)

GetDiskNumber returns the number of a disk.

func GetDiskPartitionStyle

func GetDiskPartitionStyle(disk *storage.MSFT_Disk) (int32, error)

GetDiskPartitionStyle returns the partition style of a disk.

func GetDiskPath

func GetDiskPath(disk *storage.MSFT_Disk) (string, error)

GetDiskPath returns the path of a disk.

func GetDiskSerialNumber

func GetDiskSerialNumber(disk *storage.MSFT_Disk) (string, error)

GetDiskSerialNumber returns the serial number of a disk.

func GetDiskSize

func GetDiskSize(disk *storage.MSFT_Disk) (int64, error)

GetDiskSize returns the size of a disk.

func GetISCSISessionIdentifier

func GetISCSISessionIdentifier(session *storage.MSFT_iSCSISession) (string, error)

GetISCSISessionIdentifier returns the identifier of an iSCSI session.

func GetISCSITargetNodeAddress

func GetISCSITargetNodeAddress(target *storage.MSFT_iSCSITarget) (string, error)

GetISCSITargetNodeAddress returns the node address of an iSCSI target.

func GetPartitionByVolumeUniqueID

func GetPartitionByVolumeUniqueID(volumeID string) (*storage.MSFT_Partition, error)

GetPartitionByVolumeUniqueID retrieves a specific partition from a volume identified by its unique ID.

func GetPartitionDiskNumber

func GetPartitionDiskNumber(part *storage.MSFT_Partition) (uint32, error)

GetPartitionDiskNumber retrieves the disk number associated with a given partition.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition for the WMI class definitions.

func GetPartitionSize

func GetPartitionSize(part *storage.MSFT_Partition) (int64, error)

GetPartitionSize returns the size of a partition.

func GetPartitionSupportedSize

func GetPartitionSupportedSize(part *storage.MSFT_Partition) (result int, sizeMin, sizeMax int64, status string, err error)

GetPartitionSupportedSize retrieves the minimum and maximum sizes that the partition can be resized to using the ResizePartition method.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition-getsupportedsizes for the WMI method definition.

func GetServiceDisplayName

func GetServiceDisplayName(service ServiceInterface) (string, error)

GetServiceDisplayName returns the display name of a service.

func GetServiceName

func GetServiceName(service ServiceInterface) (string, error)

GetServiceName returns the name of a service.

func GetServiceStartMode

func GetServiceStartMode(service ServiceInterface) (string, error)

GetServiceStartMode returns the start mode of a service.

func GetServiceState

func GetServiceState(service ServiceInterface) (string, error)

GetServiceState returns the state of a service.

func GetSmbGlobalMappingStatus

func GetSmbGlobalMappingStatus(inst *cim.WmiInstance) (int32, error)

GetSmbGlobalMappingStatus returns the status of an SMB global mapping.

func GetVolumeByDriveLetter

func GetVolumeByDriveLetter(driveLetter string, partitionSelectorList []string) (*storage.MSFT_Volume, error)

GetVolumeByDriveLetter retrieves a volume associated with a specific drive letter.

func GetVolumeFileSystemType

func GetVolumeFileSystemType(volume *storage.MSFT_Volume) (int32, error)

GetVolumeFileSystemType returns the file system type of a volume.

func GetVolumeSize

func GetVolumeSize(volume *storage.MSFT_Volume) (int64, error)

GetVolumeSize returns the size of a volume.

func GetVolumeSizeRemaining

func GetVolumeSizeRemaining(volume *storage.MSFT_Volume) (int64, error)

GetVolumeSizeRemaining returns the remaining size of a volume.

func GetVolumeUniqueID

func GetVolumeUniqueID(volume *storage.MSFT_Volume) (string, error)

GetVolumeUniqueID returns the unique ID (object ID) of a volume.

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound returns nil if the error is nil or a "not found" error, otherwise returns the original error.

func InitializeDisk

func InitializeDisk(disk *storage.MSFT_Disk, partitionStyle int) (int, error)

InitializeDisk initializes a RAW disk with a particular partition style.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/initialize-msft-disk for the WMI method definition.

func InvokeCimMethod

func InvokeCimMethod(namespace, class, methodName string, inputParameters map[string]interface{}) (int, map[string]interface{}, error)

InvokeCimMethod calls a static method on a specific WMI class with given input parameters, returning the method's return value, output parameters, and any error encountered.

func IsDiskOffline

func IsDiskOffline(disk *storage.MSFT_Disk) (bool, error)

IsDiskOffline returns whether a disk is offline.

func IsISCSISessionPersistent

func IsISCSISessionPersistent(session *storage.MSFT_iSCSISession) (bool, error)

IsISCSISessionPersistent returns whether an iSCSI session is persistent.

func IsISCSITargetConnected

func IsISCSITargetConnected(target *storage.MSFT_iSCSITarget) (bool, error)

IsISCSITargetConnected returns whether the iSCSI target is connected.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if it's a "not found" error.

func ListDisks

func ListDisks(selectorList []string) ([]*storage.MSFT_Disk, error)

ListDisks retrieves information about all available disks.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Disk

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-disk for the WMI class definition.

func ListDisksByTarget

func ListDisksByTarget(target *storage.MSFT_iSCSITarget) ([]*storage.MSFT_Disk, error)

ListDisksByTarget find all disks associated with an iSCSITarget. It finds out the iSCSIConnections from MSFT_iSCSITargetToiSCSIConnection association, then locate MSFT_Disk objects from MSFT_iSCSIConnectionToDisk association.

WMI association MSFT_iSCSITargetToiSCSIConnection:

iSCSIConnection                                                     | iSCSITarget
---------------                                                     | -----------
MSFT_iSCSIConnection (ConnectionIdentifier = "ffffac0cacbff010-15") | MSFT_iSCSITarget (NodeAddress = "iqn.1991-05.com...

WMI association MSFT_iSCSIConnectionToDisk:

Disk                                                               | iSCSIConnection
----                                                               | ---------------
MSFT_Disk (ObjectId = "{1}\\WIN-8E2EVAQ9QSB\root/Microsoft/Win...) | MSFT_iSCSIConnection (ConnectionIdentifier = "fff...

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsiconnection for the WMI class definition.

func ListISCSITargetPortals

func ListISCSITargetPortals(selectorList []string) ([]*storage.MSFT_iSCSITargetPortal, error)

ListISCSITargetPortals retrieves a list of iSCSI target portals.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_IscsiTargetPortal

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitargetportal for the WMI class definition.

func ListISCSITargetsByTargetPortal

func ListISCSITargetsByTargetPortal(portals []*storage.MSFT_iSCSITargetPortal) ([]*storage.MSFT_iSCSITarget, error)

ListISCSITargetsByTargetPortal retrieves all iSCSI targets from the specified iSCSI target portal using MSFT_iSCSITargetToiSCSITargetPortal association.

WMI association MSFT_iSCSITargetToiSCSITargetPortal:

iSCSITarget                                                                  | iSCSITargetPortal
-----------                                                                  | -----------------
MSFT_iSCSITarget (NodeAddress = "iqn.1991-05.com.microsoft:win-8e2evaq9q...) | MSFT_iSCSITargetPortal (TargetPortalAdd...

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitarget for the WMI class definition.

func ListISCSITargetsByTargetPortalAddressAndPort

func ListISCSITargetsByTargetPortalAddressAndPort(address string, port uint32, selectorList []string) ([]*storage.MSFT_iSCSITarget, error)

ListISCSITargetsByTargetPortalAddressAndPort retrieves ISCSI targets by address and port of an iSCSI target portal.

func ListPartitionsOnDisk

func ListPartitionsOnDisk(diskNumber, partitionNumber uint32, selectorList []string) ([]*storage.MSFT_Partition, error)

ListPartitionsOnDisk retrieves all partitions or a partition with the specified number on a disk.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Partition
  WHERE DiskNumber = '<diskNumber>'
    AND PartitionNumber = '<partitionNumber>'

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition for the WMI class definition.

func ListPartitionsWithFilters

func ListPartitionsWithFilters(selectorList []string, filters ...*query.WmiQueryFilter) ([]*storage.MSFT_Partition, error)

ListPartitionsWithFilters retrieves all partitions matching with the conditions specified by query filters.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Partition
  WHERE ...

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition for the WMI class definition.

func ListVolumes

func ListVolumes(selectorList []string) ([]*storage.MSFT_Volume, error)

ListVolumes retrieves all available volumes on the system.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Volume

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-volume for the WMI class definition.

func NewISCSITargetPortal

func NewISCSITargetPortal(targetPortalAddress string,
	targetPortalPortNumber uint32,
	initiatorInstanceName *string,
	initiatorPortalAddress *string,
	isHeaderDigest *bool,
	isDataDigest *bool) (*storage.MSFT_iSCSITargetPortal, error)

NewISCSITargetPortal creates a new iSCSI target portal.

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitargetportal-new for the WMI method definition.

func NewSmbGlobalMapping

func NewSmbGlobalMapping(remotePath, username, password string, requirePrivacy bool) (int, error)

NewSmbGlobalMapping creates a new SMB global mapping to the remote path.

Refer to https://pkg.go.dev/github.com/microsoft/wmi/server2019/root/microsoft/windows/smb#MSFT_SmbGlobalMapping for the WMI class definition.

func NewWMISession

func NewWMISession(namespace string) (*cim.WmiSession, error)

NewWMISession creates a new local WMI session for the given namespace, defaulting to root namespace if none specified.

func ParseISCSITargetPortal

func ParseISCSITargetPortal(instance *storage.MSFT_iSCSITargetPortal) (string, uint32, error)

ParseISCSITargetPortal retrieves the portal address and port number of an iSCSI target portal.

func QueryBIOSElement

func QueryBIOSElement(selectorList []string) (*cimv2.CIM_BIOSElement, error)

QueryBIOSElement retrieves the BIOS element.

The equivalent WMI query is:

SELECT [selectors] FROM CIM_BIOSElement

Refer to https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/cim-bioselement for the WMI class definition.

func QueryDiskByNumber

func QueryDiskByNumber(diskNumber uint32, selectorList []string) (*storage.MSFT_Disk, error)

QueryDiskByNumber retrieves disk information for a specific disk identified by its number.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Disk
  WHERE DiskNumber = '<diskNumber>'

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-disk for the WMI class definition.

func QueryFromWMI

func QueryFromWMI(namespace string, query *query.WmiQuery, handler InstanceHandler) error

QueryFromWMI executes a WMI query in the specified namespace and processes each result through the provided handler function. Stops processing if handler returns false or encounters an error.

func QueryISCSISessionByTarget

func QueryISCSISessionByTarget(target *storage.MSFT_iSCSITarget) (*storage.MSFT_iSCSISession, error)

QueryISCSISessionByTarget retrieves the iSCSI session from the specified iSCSI target using MSFT_iSCSITargetToiSCSISession association.

WMI association MSFT_iSCSITargetToiSCSISession:

iSCSISession                                                                | iSCSITarget
------------                                                                | -----------
MSFT_iSCSISession (SessionIdentifier = "ffffac0cacbff010-4000013700000016") | MSFT_iSCSITarget (NodeAddress = "iqn.199...

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsisession for the WMI class definition.

func QueryISCSITarget

func QueryISCSITarget(address string, port uint32, nodeAddress string) (*storage.MSFT_iSCSITarget, error)

QueryISCSITarget retrieves the iSCSI target from the specified portal address, portal and node address.

func QueryISCSITargetPortal

func QueryISCSITargetPortal(address string, port uint32, selectorList []string) (*storage.MSFT_iSCSITargetPortal, error)

QueryISCSITargetPortal retrieves information about a specific iSCSI target portal identified by its network address and port number.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_IscsiTargetPortal
  WHERE TargetPortalAddress = '<address>'
    AND TargetPortalPortNumber = '<port>'

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitargetportal for the WMI class definition.

func QueryInstances

func QueryInstances(namespace string, query *query.WmiQuery) ([]*cim.WmiInstance, error)

QueryInstances retrieves all WMI instances matching the given query in the specified namespace.

func QueryServiceByName

func QueryServiceByName(name string, selectorList []string) (*cimv2.Win32_Service, error)

QueryServiceByName retrieves a specific service by its name.

The equivalent WMI query is:

SELECT [selectors] FROM Win32_Service

Refer to https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-service for the WMI class definition.

func QuerySmbGlobalMappingByRemotePath

func QuerySmbGlobalMappingByRemotePath(remotePath string) (*cim.WmiInstance, error)

QuerySmbGlobalMappingByRemotePath retrieves the SMB global mapping from its remote path.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_SmbGlobalMapping

Refer to https://pkg.go.dev/github.com/microsoft/wmi/server2019/root/microsoft/windows/smb#MSFT_SmbGlobalMapping for the WMI class definition.

func QueryVolumeByUniqueID

func QueryVolumeByUniqueID(volumeID string, selectorList []string) (*storage.MSFT_Volume, error)

QueryVolumeByUniqueID retrieves a specific volume by its unique identifier, returning the first volume that matches the given volume ID.

The equivalent WMI query is:

SELECT [selectors] FROM MSFT_Volume

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-volume for the WMI class definition.

func RefreshDisk

func RefreshDisk(disk *storage.MSFT_Disk) (int, string, error)

RefreshDisk Refreshes the cached disk layout information.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-disk-refresh for the WMI method definition.

func RemoveISCSITargetPortal

func RemoveISCSITargetPortal(instance *storage.MSFT_iSCSITargetPortal) (int, error)

RemoveISCSITargetPortal removes an iSCSI target portal.

Refer to https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitargetportal-remove for the WMI method definition.

func RemoveSmbGlobalMappingByRemotePath

func RemoveSmbGlobalMappingByRemotePath(remotePath string) error

RemoveSmbGlobalMappingByRemotePath removes an SMB global mapping matching to the remote path.

Refer to https://pkg.go.dev/github.com/microsoft/wmi/server2019/root/microsoft/windows/smb#MSFT_SmbGlobalMapping for the WMI class definition.

func RescanDisks

func RescanDisks() (int, error)

RescanDisks rescans all changes by updating the internal cache of software objects (that is, Disks, Partitions, Volumes) for the storage setting.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-storagesetting-updatehoststoragecache for the WMI method definition.

func ResizePartition

func ResizePartition(part *storage.MSFT_Partition, size int64) (int, string, error)

ResizePartition resizes a partition.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition-resize for the WMI method definition.

func SetISCSISessionChapSecret

func SetISCSISessionChapSecret(mutualChapSecret string) (int, error)

SetISCSISessionChapSecret sets a CHAP secret key for use with iSCSI initiator connections.

Refer https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsitarget-disconnect for the WMI method definition.

func SetPartitionState

func SetPartitionState(part *storage.MSFT_Partition, online bool) (int, string, error)

SetPartitionState takes a partition online or offline.

Refer to https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition-online and https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/msft-partition-offline for the WMI method definition.

func UnregisterISCSISession

func UnregisterISCSISession(session *storage.MSFT_iSCSISession) (int, error)

UnregisterISCSISession unregisters the iSCSI session so that it is no longer persistent.

Refer https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsidisc/msft-iscsisession-unregister for the WMI method definition.

func WithCOMThread

func WithCOMThread(fn func() error) error

WithCOMThread runs the given function `fn` on a locked OS thread with COM initialized using COINIT_MULTITHREADED.

This is necessary for using COM/OLE APIs directly (e.g., via go-ole), because COM requires that initialization and usage occur on the same thread.

It performs the following steps:

  • Locks the current goroutine to its OS thread
  • Calls ole.CoInitializeEx with COINIT_MULTITHREADED
  • Executes the user-provided function
  • Uninitializes COM
  • Unlocks the thread

If COM initialization fails, or if the user's function returns an error, that error is returned by WithCOMThread.

Types

type InstanceHandler

type InstanceHandler func(instance *cim.WmiInstance) (bool, error)

type ServiceInterface

type ServiceInterface interface {
	GetPropertyName() (string, error)
	GetPropertyDisplayName() (string, error)
	GetPropertyState() (string, error)
	GetPropertyStartMode() (string, error)
	GetDependents() ([]ServiceInterface, error)
	StartService() (result uint32, err error)
	StopService() (result uint32, err error)
	Refresh() error
}

type Win32Service

type Win32Service struct {
	*cimv2.Win32_Service
}

Win32Service wraps the WMI class Win32_Service (mainly for testing)

func (*Win32Service) GetDependents

func (s *Win32Service) GetDependents() ([]ServiceInterface, error)

type Win32ServiceFactory

type Win32ServiceFactory struct {
}

func (Win32ServiceFactory) GetService

func (impl Win32ServiceFactory) GetService(name string) (ServiceInterface, error)

Jump to

Keyboard shortcuts

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