Retrive ProcessorID, HardDiskID, LANCardID, MotherboardID using c#

Many times it is required to retrive processor, harddisk, lancard,
motherboard
identification for the purpose of Licenseing Issue.
So my code is helpful for you if you interested to manage license for
your application. You just receive clients webservers the above
information
first time, latter when User want's to lunch his/her appliation, then
you check it with the help of webserver which is hosted by you.

Requirement
==========
If you want to implement that model then you must host and live your
webserer. ohterwise clients app does not work. If you not like that then
you may change that model and implement any dirrerent technic for
license checking.


The code is written by dotnet 2.0/3.0/3.5
===========================================

using System.Management;
using System.Management.Instrumentation;

public string GetProcessorID()
{
string processorID = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_Processor");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name.Equals("ProcessorId"))
{
processorID = (String)prop.Value;
break;
}
}
}
return processorID;
}

public string GetDiskID()
{
string diskID = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_DiskDrive");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name == "Caption")
{
diskID = (String)prop.Value;
break;
}
}
}
return diskID;
}


public string GetMotherBoardSerialNumber()
{
string serialNumber = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_BaseBoard");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name == "SerialNumber")
return (String)prop.Value;
}
}
return serialNumber;
}



public string GetMacAddress()
{
string result = string.Empty;

foreach (NetworkInterface obj in
NetworkInterface.GetAllNetworkInterfaces())
{
if (obj.NetworkInterfaceType !=
NetworkInterfaceType.Loopback)
{
result = obj.GetPhysicalAddress().ToString();
break;
}
}
return result;
}



No comments: