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.
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.