I'm trying to use system.management in a C# windows forms app in VS 2017, but it just won't work. Here is a code sample:
using System;
using System.Windows.Forms;
using System.Management;
namespace MyWMIapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void okButton_Click(object sender, EventArgs e)
{
ManagementScope scope = new ManagementScope(@”\\MyComputerName\root\CIMV2″);
}
}
}
At: "using System.Management;" it tells me: this is not needed/used.
At: "ManagementScope scope = ......" it tells me: not found (maybe a missing using-Directive), and is red underlined.
Both is obviously wrong. I'm loading it and I'm using it. Why don't both lines "see" each other?
Add reference to System.Management.dll to your project.