fix: activate COM classes by CLSID instead of ProgID (#2546)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jan-Otto Kröpke <mail@jkroepke.de>
Signed-off-by: safster123 <97958730+safster123@users.noreply.github.com>
This commit is contained in:
safster123
2026-10-08 13:30:20 +02:00
committed by GitHub
co-authored by Claude Opus 5.5 Jan-Otto Kröpke
parent 831436f48d
commit 16aa107c9f
2 changed files with 21 additions and 8 deletions
@@ -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
}
+11 -1
View File
@@ -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)