diff --git a/internal/collector/scheduled_task/scheduled_task.go b/internal/collector/scheduled_task/scheduled_task.go index 685af589..9f5dc41e 100644 --- a/internal/collector/scheduled_task/scheduled_task.go +++ b/internal/collector/scheduled_task/scheduled_task.go @@ -284,7 +284,15 @@ func (c *Collector) collectMetrics(ch chan<- prometheus.Metric, scheduledTasks S } } -const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1" +// CLSID_TaskScheduler {0F87369F-A4E5-4CFC-BD3E-73E6154572DD}: https://github.com/microsoft/win32metadata/blob/76c04c2021ef4a831a6f1e06d9566002d746139b/generation/WinSDK/RecompiledIdlHeaders/um/taskschd.h#L10359 +// +//nolint:gochecknoglobals // CLSID, not ProgID: go-ole's CLSIDFromProgID can free the ProgID buffer mid-call +var taskSchedulerCLSID = ole.GUID{ + Data1: 0x0F87369F, + Data2: 0xA4E5, + Data3: 0x4CFC, + Data4: [8]byte{0xBD, 0x3E, 0x73, 0xE6, 0x15, 0x45, 0x72, 0xDD}, +} // S_FALSE is returned by CoInitialize if it was already called on this thread. const S_FALSE = 0x00000001 @@ -308,12 +316,7 @@ func getScheduledTasks() (ScheduledTasks, error) { defer ole.CoUninitialize() - schedClassID, err := ole.ClassIDFrom(SCHEDULED_TASK_PROGRAM_ID) - if err != nil { - return scheduledTasks, err - } - - taskSchedulerObj, err := ole.CreateInstance(schedClassID, nil) + taskSchedulerObj, err := ole.CreateInstance(&taskSchedulerCLSID, nil) if err != nil || taskSchedulerObj == nil { return scheduledTasks, err } diff --git a/internal/collector/update/update.go b/internal/collector/update/update.go index e080680a..72894845 100644 --- a/internal/collector/update/update.go +++ b/internal/collector/update/update.go @@ -38,6 +38,16 @@ import ( const Name = "update" +// CLSID_UpdateSession {4CB43D7F-7EEE-4906-8698-60DA1C38F2FE}: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-uamg/e839e7e0-1795-451b-94ef-abacd6cbecac +// +//nolint:gochecknoglobals // CLSID, not ProgID: go-ole's CLSIDFromProgID can free the ProgID buffer mid-call +var updateSessionCLSID = ole.GUID{ + Data1: 0x4CB43D7F, + Data2: 0x7EEE, + Data3: 0x4906, + Data4: [8]byte{0x86, 0x98, 0x60, 0xDA, 0x1C, 0x38, 0xF2, 0xFE}, +} + type Config struct { Online bool `yaml:"online"` ScrapeInterval time.Duration `yaml:"scrape-interval"` @@ -191,7 +201,7 @@ func (c *Collector) scheduleUpdateStatus(ctx context.Context, logger *slog.Logge defer ole.CoUninitialize() // Create a new instance of the WMI object - sessionObj, err := oleutil.CreateObject("Microsoft.Update.Session") + sessionObj, err := ole.CreateInstance(&updateSessionCLSID, ole.IID_IUnknown) if err != nil { initErrCh <- fmt.Errorf("create Microsoft.Update.Session: %w", err)