import subprocess def set_native_brightness(percentage): """ Sets the display brightness using the native classic WMI object via PowerShell. """ percentage = max(0, min(100, int(percentage))) # Using Get-WmiObject instead of Get-CimInstance to properly expose the native method command = f"(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(0, {percentage})" try: subprocess.run(["powershell", "-Command", command], capture_output=True, text=True, check=True) print(f"Successfully set native brightness to {percentage}%") except subprocess.CalledProcessError as e: print(f"Error changing brightness: {e.stderr.strip()}") if __name__ == "__main__": # Test with 50% brightness set_native_brightness(0)