mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -114,13 +115,12 @@ namespace PowerDisplay.Common.Drivers.WMI
|
|||||||
{
|
{
|
||||||
// Call WmiSetBrightness method
|
// Call WmiSetBrightness method
|
||||||
// Parameters: Timeout (uint32), Brightness (uint8)
|
// Parameters: Timeout (uint32), Brightness (uint8)
|
||||||
// Note: Using int instead of byte to avoid WBEM_E_TYPE_MISMATCH (0x80041005)
|
// Note: WmiLight requires string values for method parameters
|
||||||
// Some WMI driver implementations expect VT_I4 instead of VT_UI1
|
|
||||||
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
||||||
using (WmiMethodParameters inParams = method.CreateInParameters())
|
using (WmiMethodParameters inParams = method.CreateInParameters())
|
||||||
{
|
{
|
||||||
inParams.SetPropertyValue("Timeout", 0u);
|
inParams.SetPropertyValue("Timeout", "0");
|
||||||
inParams.SetPropertyValue("Brightness", brightness);
|
inParams.SetPropertyValue("Brightness", brightness.ToString(CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
uint result = obj.ExecuteMethod<uint>(
|
uint result = obj.ExecuteMethod<uint>(
|
||||||
method,
|
method,
|
||||||
@@ -367,8 +367,8 @@ namespace PowerDisplay.Common.Drivers.WMI
|
|||||||
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
|
||||||
using (WmiMethodParameters inParams = method.CreateInParameters())
|
using (WmiMethodParameters inParams = method.CreateInParameters())
|
||||||
{
|
{
|
||||||
inParams.SetPropertyValue("Timeout", 0u);
|
inParams.SetPropertyValue("Timeout", "0");
|
||||||
inParams.SetPropertyValue("Brightness", 50);
|
inParams.SetPropertyValue("Brightness", "50");
|
||||||
obj.ExecuteMethod<uint>(method, inParams, out WmiMethodParameters outParams);
|
obj.ExecuteMethod<uint>(method, inParams, out WmiMethodParameters outParams);
|
||||||
return false; // If successful, no elevation required
|
return false; // If successful, no elevation required
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user