RSS

Get Hardware Information in C# Application

07 Oct

Making sure your software is used by legal buyers is a concern for programmers around the world. My professor once said that we shouldn�t give 100% of our code to the users because there are people out there that are smart enough to decompile our programs and find the various verification algorithms used. He suggested that we give users 99% of our software, but keep the remaining 1% to ourselves. This 1% is the verification algorithm to confirm only valid users can use the program; this is commonly known as �activation.�

Activation is good, but it means our software users will need to have Internet access and that means small programmers like us have to set up a server that can validate users. Of course, only big companies with big clients can afford to do this. For the rest of us, we have to think of other ways.

One method programmers have used since the DOS era was to bind their software to the Hard Drive Volume Serial Number. This is not a good choice, as later we all find out that every time we format the same hard drive, a new Volume Serial Number is generated.

All bellow code, you need to add Window Reference :: Project -> Add References… and then select System.Management .  After that, you add import namespace into your source code by:

using System.Management;

Motherboard Serial Number


private string GetMotherboardSerialNumber()
 {
 ManagementObjectSearcher searcher = new ManagementObjectSearcher
 ("SELECT SerialNumber, Product FROM Win32_BaseBoard");

 ManagementObjectCollection information = searcher.Get();
 string serialNumber = string.Empty;

 foreach (ManagementObject obj in information)
 {
 if (obj.Properties["SerialNumber"].Value.ToString().Trim() != string.Empty)
 serialNumber = obj.Properties["SerialNumber"].Value.ToString().Trim();
 else
 serialNumber = obj.Properties["Product"].Value.ToString().Trim();
 break;
 }

 searcher.Dispose();

 return serialNumber;
 }

Reference by: http://www.codegain.com/index.php?option=com_content&view=article&id=345

Hard Disk Drive Serial Number


private string GetHDDSerialNumber()
{
  string hdno = "";
  ArrayList hdCollection = new ArrayList();
  ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM   Win32_PhysicalMedia");
  int i = 0;
  foreach(ManagementObject wmi_HD in searcher.Get())
  {
	// get the hard drive from collection
	// using index
	HardDrive hd = (HardDrive)hdCollection[i];

	// get the hardware serial no.
	if (wmi_HD["SerialNumber"] == null)
		hdno = "None";
	else
		hdno = wmi_HD["SerialNumber"].ToString();

	i++;
  }
  return hdno;
}

Reference: http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx

dsfdsaff

 

About sochinda

I really like new technology!!
1 Comment

Posted by on October 7, 2009 in Window Application

 

One Response to Get Hardware Information in C# Application

  1. Pankaj Singh

    November 15, 2011 at 7:30 PM

    Hi,
    Your article are really awesome.actually i was in search for some good articles on Operating system info and processor info in c# and finally i got one.
    The most important is the simplicity which will be very helpful for the beginners. I have found another nice post over internet related to this post which also explain nicely, please visit following link for more details of that post..

    http://www.mindstick.com/Blog/176/Displaying%20computer%20system%20information%20using%20C

    Thanks Everyone for your help.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.