From 9df59c75cd2684ca2ae3dd4a2838024a943381cb Mon Sep 17 00:00:00 2001 From: Rahman Mousavian Date: Tue, 26 Oct 2021 01:32:57 +1100 Subject: [PATCH] Using CoInitializeEx, Locking OLE calls to the OS thread Signed-off-by: Rahman Mousavian --- collector/scheduled_task.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/collector/scheduled_task.go b/collector/scheduled_task.go index 9ab766b2..470472c4 100644 --- a/collector/scheduled_task.go +++ b/collector/scheduled_task.go @@ -5,6 +5,7 @@ package collector import ( "fmt" "regexp" + "runtime" "strings" ole "github.com/go-ole/go-ole" @@ -164,7 +165,10 @@ const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1" const S_FALSE = 0x00000001 func getScheduledTasks() (scheduledTasks ScheduledTasks, err error) { - err = ole.CoInitialize(0) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED) if err != nil { code := err.(*ole.OleError).Code() if code != ole.S_OK && code != S_FALSE {