mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
Fix WMI parameter type mismatch in WmiSetBrightness
Updated the `WmiSetBrightness` method to pass `Timeout` and `Brightness` parameters as strings instead of numeric types to ensure compatibility with WMI driver implementations that require string values. Updated comments to reflect this change and clarify the reasoning behind it.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -114,13 +115,12 @@ namespace PowerDisplay.Common.Drivers.WMI
|
||||
{
|
||||
// Call WmiSetBrightness method
|
||||
// Parameters: Timeout (uint32), Brightness (uint8)
|
||||
// Note: Using int instead of byte to avoid WBEM_E_TYPE_MISMATCH (0x80041005)
|
||||
// Some WMI driver implementations expect VT_I4 instead of VT_UI1
|
||||
// Note: WmiLight requires string values for method parameters
|
||||
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
||||
using (WmiMethodParameters inParams = method.CreateInParameters())
|
||||
{
|
||||
inParams.SetPropertyValue("Timeout", 0u);
|
||||
inParams.SetPropertyValue("Brightness", brightness);
|
||||
inParams.SetPropertyValue("Timeout", "0");
|
||||
inParams.SetPropertyValue("Brightness", brightness.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
uint result = obj.ExecuteMethod<uint>(
|
||||
method,
|
||||
@@ -367,8 +367,8 @@ namespace PowerDisplay.Common.Drivers.WMI
|
||||
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
||||
using (WmiMethodParameters inParams = method.CreateInParameters())
|
||||
{
|
||||
inParams.SetPropertyValue("Timeout", 0u);
|
||||
inParams.SetPropertyValue("Brightness", 50);
|
||||
inParams.SetPropertyValue("Timeout", "0");
|
||||
inParams.SetPropertyValue("Brightness", "50");
|
||||
obj.ExecuteMethod<uint>(method, inParams, out WmiMethodParameters outParams);
|
||||
return false; // If successful, no elevation required
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user