C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Application windows, menus & toolbars »

Retrieving hard disk details from remote machine


Posted Date: 15 Sep 2009    Resource Type: Code Snippets    Category: Application windows, menus & toolbars
Author: satyaMember Level: Diamond    
Rating: 1 out of 5Points: 7



Retrieving hard disk details from remote machine




using System.Management;
using System.Threading;

DataTable oDt = new DataTable();


public Form1()
{
oDt.Columns.Add("System Name");
oDt.Columns.Add("Software/Hardware");
oDt.Columns.Add("Caption");
oDt.Columns.Add("Configuration");
}

private void btnLstSoftwares_Click(object sender, EventArgs e)
{
string[] sArr = null;
for (int i = 0; i < comboBox1.Items.Count; i++)
{
sArr = comboBox1.Items[i].ToString().Split('=');
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThread), sArr[1].ToString());
}
}

public void MyThread(object oSysName)
{
lock (this)
{
string sSysName = (string)oSysName;
try
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = "administrator";
connection.Password = "admin";

ManagementScope scope = new ManagementScope("\\\\" + sSysName.ToString() + "\\root\\CIMV2", connection);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_DiskDrive");
ManagementObjectSearcher searcherRAM = new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())
{
DataRow oDr1;
oDr1 = oDt.NewRow();
oDr1[0] = sSysName;
oDr1[1] = "HardDisk";
oDr1[2] = "Caption";
oDr1[3] = queryObj["Caption"].ToString();
oDt.Rows.Add(oDr1);

DataRow oDr2;
oDr2 = oDt.NewRow();
oDr2[0] = sSysName;
oDr2[1] = "HardDisk";
oDr2[2] = "PNPDeviceId";
oDr2[3] = queryObj["PNPDeviceId"].ToString();
oDt.Rows.Add(oDr2);

DataRow oDr3;
oDr3 = oDt.NewRow();
oDr3[0] = sSysName;
oDr3[1] = "HardDisk";
oDr3[2] = "Size";
oDr3[3] = queryObj["Size"].ToString();
oDt.Rows.Add(oDr3);
}
catch (ManagementException oMnEx)
{
DataRow oDr1;
oDr1 = oDt.NewRow();
oDr1[0] = sSysName;
oDr1[1] = "Error";
oDr1[2] = "";
oDr1[3] = oMnEx.Message.ToString();
oDt.Rows.Add(oDr1);
}
catch (System.UnauthorizedAccessException unauthorizedErr)
{
DataRow oDr1;
oDr1 = oDt.NewRow();
oDr1[0] = sSysName;
oDr1[1] = "Error";
oDr1[2] = "";
oDr1[3] = unauthorizedErr.Message.ToString();
oDt.Rows.Add(oDr1);

}
catch (Exception oEx)
{
DataRow oDr1;
oDr1 = oDt.NewRow();
oDr1[0] = sSysName;
oDr1[1] = "Error";
oDr1[2] = "";
oDr1[3] = oEx.Message.ToString();
oDt.Rows.Add(oDr1);

}
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = oDt;
}
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Retrieving hard disk details from remote machine  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Change the order of columns in the DataGridView
Previous Resource: Retrieving software details from remote machine
Return to Discussion Resource Index
Post New Resource
Category: Application windows, menus & toolbars


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use