-1

Okey, my code for checking HWID is working fine, but when it comes the part to pass the the HWID in to string its not working, its returning blank.

This is the code i use

private void Form1_Load(object sender, EventArgs e)
    {
        string HWID = string.Empty;//creating a empty string
        ManagementClass Management = new ManagementClass("win32_processor");//declaring the system management calss
        ManagementObjectCollection MObject = Management.GetInstances();//decalring the system management object collection 
        foreach (ManagementObject mob in MObject)//having a foreach loop
        {
            if (string.IsNullOrEmpty(HWID))
            {
                HWID = mob.GetPropertyValue("processorID").ToString();//converting the HWID to string
                break;
            }
        }

     }

    private void alphaBlendTextBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
       string loginUrl = "http://xxxxxx.xyz/customapi.php?username=" + alphaBlendTextBox1.Text + "&password=" + alphaBlendTextBox2.Text + "&hid=" + hwid + "&apiKey=APIKEYHERE&hid=" + HWID + "&ver=2";

to make everything even more clear im trying to make API call, everything is fine but when it comes to the HWID its failing.

//edit

I keep failing, if anyone williing to rewrite and fix the code ill be happy.. Thanks!

CEED
  • 1
  • 3

2 Answers2

1

You have to declare the string "HWID" outside of Form1_Load.

So it looks like

string HWID = string.Empty;//creating a empty string

private void Form1_Load(object sender, EventArgs e)
{
    ManagementClass Management = new ManagementClass("win32_processor");//declaring the system management calss
    ManagementObjectCollection MObject = Management.GetInstances();//decalring the system management object collection 
    foreach (ManagementObject mob in MObject)//having a foreach loop
    {
        if (string.IsNullOrEmpty(HWID))
        {
            HWID = mob.GetPropertyValue("processorID").ToString();//converting the HWID to string
            break;
        }
    }

 }

I always did it like this

string HWID = String.Empty;
ManagementObjectSearcher moSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject mngObj in moSearcher.Get())
{
   HWID = mngObj["ProcessorId"].ToString();
}
aequabit
  • 50
  • 1
  • 7
  • I kinda fix it, now the issue is that ii need to make this work on 64/32bit PC. Thiis works okey for 32bit, but on 64bit pc its returning same ID no matter what – CEED Oct 09 '16 at 20:27
0

You no need set HWID string to null if it's not static or not Accessable from another method or class

I know anyone have some coding styles but if your write your comments above your code it's more clean and readable

See this Question and This Tutorial

And if i want get HardwareID, I create a method for get it

moien
  • 999
  • 11
  • 26