We have some code to counter the brightness dimming on laptops. It relies on System.Management calls. It works fine on a laptop but on a PC without power management it throws an Exception: System.Management.ManagementException "not supported" I do not want to make it work (for that see System.Management.ManagementException), but want to just detect the case that it is not supported and then exit early to avoid having the exception thrown. Is there a way to do so?
I tried looking for the same or similar issues on stackoverflow and the rest of the internet.
Currently I'm using try catch to handle this, but would prefer not having to rely on that.
System.Management.ManagementScope s = new System.Management.ManagementScope("root\\WMI");
System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightness");
System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);
try {
System.Management.ManagementObjectCollection moc = mos.Get();
foreach (System.Management.ManagementObject o in moc) { // exception here
...
actual: System.Management.ManagementException "not supported"
expected: should test support earlier and exit if not supported