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

Advertisements
 
5 Comments

Posted by on October 7, 2009 in Window Application

 

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

     
  2. best dog clipper

    July 22, 2013 at 9:41 PM

    Great site! I really love how it is easy to read. I am curious how I could
    be notified when a new post has been made. I have registered to your feed which should do!
    Have a great day and please excuse my poor english!

     
  3. astral projection for beginners by edain mccoy download

    September 7, 2013 at 7:28 PM

    An outstanding share! I have just forwarded this onto a coworker who has been doing a little research on this.
    And he actually ordered me lunch due to the fact
    that I stumbled upon it for him… lol. So let me reword this….

    Thanks for the meal!! But yeah, thanx for spending the time to discuss this topic here on your blog.

     
  4. Youtube.Com

    February 19, 2014 at 7:53 AM

    We’ll keep you updated with information as
    it becomes available. What MLB 12: The Show is bringing this year is a slew of
    new features and enhancements to make your virtual baseball experience unlike
    any other you’ve ever experienced. Here, you can edit the name among other information like album, artist, genre and
    attached picture.

     
  5. serviced apartments in chennai for rent

    October 5, 2014 at 1:15 AM

    One thing that goes in complete favor of corporate apartments is that there are no hidden charges.
    Quay Apartment is an excellent leader to providing holiday service apartments Manchester
    and cheap hotels manchester city centre in United
    Kingdom. All the hotels provide daily housekeeping services to the guests.

    With corporate travel soaring inexorably, the latest entrant in the Indian hospitality
    industry has earned the plaudits of the business community
    primarily because of its inimitable comfort and privacy.

     

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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: