1

I am trying to call the WmiSetBrightness method of the WmiMonitorBrightnessMethods class:

https://learn.microsoft.com/en-us/windows/desktop/wmicoreprov/wmisetbrightness-method-in-class-wmimonitorbrightnessmethods

with the help of https://github.com/go-ole/go-ole and example code from Calling a method of a WMI Class

I don't know why it keeps returning the error:

wmi: error calling method WmiSetBrightness: Exception occurred. (Invalid method Parameter(s) )

I have searched for a while but I still can't figure out the correct way to pass the two parameters Timeout and Brightness.

My code is as followed:

func main() {
    err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
    if err != nil {
        log.Fatal(err)
    }

    unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
    if err != nil {
        log.Fatal(err)
    }
    defer unknown.Release()

    wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
    if err != nil {
        log.Fatal(err)
    }
    defer wmi.Release()

    serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", nil, `root/WMI`)
    if err != nil {
        log.Fatal(err)
    }
    service := serviceRaw.ToIDispatch()
    defer serviceRaw.Clear()

    typeName := "WmiMonitorBrightnessMethods"
    typeRaw, err := oleutil.CallMethod(service, "Get", typeName)
    if err != nil {
        log.Fatalf("wmi: error fetching type %v: %v", typeName, err)
    }
    typeResult := typeRaw.ToIDispatch()
    defer typeRaw.Clear()

    methodName := "WmiSetBrightness"
    // Set Brightness value to 20 with the Timeout 1
    methodRaw, err := oleutil.CallMethod(typeResult, methodName, 1, 20)
    if err != nil {
        log.Fatalf("wmi: error calling method %v: %v", methodName, err)
    }
    item := methodRaw.ToIDispatch()
    defer methodRaw.Clear()
    _ = item
}
kevin.bui
  • 51
  • 1
  • 7
  • Take a look at [https://stackoverflow.com/questions/47333195/change-brightness-using-wmi](https://stackoverflow.com/questions/47333195/change-brightness-using-wmi). Perhaps the operation is not supported? – putu Nov 23 '18 at 06:54

0 Answers0