Hi,
Some of this code is from other people and I've just compiled it together and changed to C# as well as adding online/offline protection. There's two ways to doing this. You will need to host a database.txt file on a website which contains the valid HWID's.
What is a HWID?
http://www.webopedia.com/TERM/H/HWID.html
First one :
Step : 1
This is to retrieve the HWID of the computer and paste it into a textBox.(button1_Click) Paste it inside the { and the } when you double click the Get HWID button.
Code:
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (string.IsNullOrEmpty(cpuInfo))
{
cpuInfo = mo["ProcessorID"].ToString();
break;
}
}
textBox1.Text = cpuInfo;
Step : 2
This is to retrieve the list of HWID's from your database.txt file and check it to the current computers.(button2_Click) Paste it inside the { and the } when you double click the Check/Login button.
Code:
try
{
string cpuInfo = string.Empty;
WebClient webClient = new WebClient();
string strings = null;
strings = webClient.DownloadString("http://website.com/Database.txt");
webClient.Dispose();
if (strings.Contains(cpuInfo))
{
// If the HWID is in the file then it will return this. MessageBox.Show("HWID Valid", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
else
{
// If the HWID isn't in the file then it will return this.
MessageBox.Show("HWID Invalid", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
catch (Exception)
{
// If not connected to the internet or can't connect to the site then it will return this.
MessageBox.Show("Unable To Retrieve HWID", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
Second One :
Step : 1
This is to retrieve the HWID of the computer and paste it into a textBox.(button1_Click) Paste it inside the { and the } when you double click the Get HWID button.
Code:
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (string.IsNullOrEmpty(cpuInfo))
{
cpuInfo = mo["ProcessorID"].ToString();
break;
}
}
textBox1.Text = cpuInfo;
Step : 2
This will handle the checking of if you are connected to the internet.
Code:
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out Description, int ReservedValue ) ;
public static bool isConnectedToTheInternet( )
{
int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;
}
Step : 3
This is to retreive the list of HWID's from your database.txt file and chek it to the current computers.(button2_Click) Paste it inside the { and the } when you double click the Check/Login button.
Code:
if (!isConnectedToTheInternet()) //Checks if it isn't connected to internet
{
MessageBox.Show("Unable To Retrieve HWID", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();
} else
{ //Downloads the database.txt file.
string cpuInfo = string.Empty;
WebClient webClient = new WebClient();
string strings = null;
strings = webClient.DownloadString("http://website.com/Database.txt");
webClient.Dispose();
if (strings.Contains(cpuInfo))//If it contains the HWID in the database.txt file.
{
MessageBox.Show("HWID Valid", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
if (!strings.Contains(cpuInfo))//If it doesn't contain the HWID in the database.txt file.(Could use else method)
{
{
MessageBox.Show("HWID Invalid", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();
}
}
}
}
That's it, I recommend the first one for beginners or novice users and second for more experienced users as you have more control.
Enjoy!