0

I have the following...

using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class CallWMIMethod
    {
        public static ushort GetMonitorBrightness() {
            using (var mclass = new ManagementClass("WmiMonitorBrightness")) {
                mclass.Scope = new ManagementScope(@"\\.\root\wmi");
                using (var instances = mclass.GetInstances()) {
                    foreach (ManagementObject instance in instances) {
                        return (byte) instance.GetPropertyValue("CurrentBrightness");
                    }
                }
            }
            return 0;
        }

        public static void SetMonitorBrightness(ushort brightness) {
            using (var mclass = new ManagementClass("WmiMonitorBrightnessMethods")) {
                mclass.Scope = new ManagementScope(@"\\.\root\wmi");
                using (var instances = mclass.GetInstances()) {
                    foreach (ManagementObject instance in instances) {
                        object[] args = new object[] { 1, brightness };
                        instance.InvokeMethod("WmiSetBrightness", args);
                    }
                }
            }
        }

        public static void Main()
        {
            Console.WriteLine (GetMonitorBrightness());
        }
    }
}

Which is a very basic thing that gets the monitor brightness using WMI. But I can't seem to run it, I keep getting errors at foreach (ManagementObject instance in instances) { about System.Management.ManagementException - Not supported I'm not sure what is going on. I am using monodevelop to compile it. It compiles fine, just dies when trying to run. I'm on Windows 7 so it's not that. WMI service is running.

I'm not sure what's going on.

Steven
  • 13,250
  • 33
  • 95
  • 147

2 Answers2

1

The Mono compatibility page explicitly states that System.Management is not implemented nor supported, as there is no counter part of WMI and so on for Linux.

http://mono-project.com/Compatibility

You have to wrap over Linux native APIs to achieve what you attempt to do on Windows, which is obvious another question you should post.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

The problem is probably due to your own graphics card drivers (are they up-to-date)?

Googling the web (looking for "WmiMonitorBrightness not supported") there is a plenty of users having your own problem, in particular on laptop/notebooks (some of them fixed after upgrading the video drivers to last version... did you?).

Anyway there is a very similar question already on StackOverflow: you can find it here.

Community
  • 1
  • 1
Morix Dev
  • 2,700
  • 1
  • 28
  • 49