System.Management namespace önce add reference ile ekleyip daha sonrada aynı namespace yi kod kısmının başına import ettikten ve sayfaya bir adet treeView ekleyin...
Not: Eğer uzak bilgisayara bağlanmak istemiyorsanız connectionOptions ve ManagementScope kullanmanıza gerek yok..
connectionOptions connection = new ConnectionOptions();
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.EnablePrivileges = true;
connection.Username = textUserID.Text;
connection.Password = textPassword.Text;
ManagementScope scope = new ManagementScope("\\\\Bilgisayar ismi\\root\\cimv2", connection);
scope.Connect();
if (scope.IsConnected == false)
{
MessageBox.Show("WMI namespace bağlanamıyor.");
}
//burda disk bilgilerini aldým
treeView1.Nodes.Clear();
treeView1.Visible = true;
mos.Scope = scope;
mos.Query = new ObjectQuery("SELECT * From Win32_LogicalDisk");
foreach (ManagementObject mo in mos.Get())
{
treeView1.Nodes.Add(mo["Caption"].ToString(), mo["Caption"].ToString());
}
foreach (TreeNode tn in treeView1.Nodes)
{
foreach (ManagementObject mo in mos.Get())
{
foreach (PropertyData pd in mo.Properties)
{
if (mo["Caption"].ToString() == tn.Text)
{
if (mo[pd.Name] != null)
{
tn.Nodes.Add(pd.Name + ": " + mo[pd.Name].ToString());
}
}
}
}
}
//burda bitirdim
}
catch (ManagementException err)
{
MessageBox.Show(err.Message);
}