Using CoInitializeEx, Locking OLE calls to the OS thread

Signed-off-by: Rahman Mousavian <rahman.mousavian@oracle.com>
This commit is contained in:
Rahman Mousavian 2021-10-26 01:32:57 +11:00
parent e112446ce9
commit 9df59c75cd
No known key found for this signature in database
GPG Key ID: 642A43DBBC74CCCC
1 changed files with 5 additions and 1 deletions

View File

@ -5,6 +5,7 @@ package collector
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"runtime"
"strings" "strings"
ole "github.com/go-ole/go-ole" ole "github.com/go-ole/go-ole"
@ -164,7 +165,10 @@ const SCHEDULED_TASK_PROGRAM_ID = "Schedule.Service.1"
const S_FALSE = 0x00000001 const S_FALSE = 0x00000001
func getScheduledTasks() (scheduledTasks ScheduledTasks, err error) { 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 { if err != nil {
code := err.(*ole.OleError).Code() code := err.(*ole.OleError).Code()
if code != ole.S_OK && code != S_FALSE { if code != ole.S_OK && code != S_FALSE {