Hyperion
Founder
Threw this together this morning for a quick example of pulling some hardware serials via WMI
and creating a unique HWID string to use for a login system or just getting users to
generate their unique ID for you to use in a database. Thanks to Hammer for the
Substring hint. The last 10 characters of each serial is used.
For the RAM, I used the part number ID which is also unique. Only because
for some reason I only get a null value from my SerialNumber (0x0000000).
String format is: ram-cpu-motherboard-harddrive
A screenie of it in action:
Used References:
Here is the code showing each ID return separately:
Enjoy
and creating a unique HWID string to use for a login system or just getting users to
generate their unique ID for you to use in a database. Thanks to Hammer for the
Substring hint. The last 10 characters of each serial is used.
For the RAM, I used the part number ID which is also unique. Only because
for some reason I only get a null value from my SerialNumber (0x0000000).
String format is: ram-cpu-motherboard-harddrive
A screenie of it in action:
Used References:
Code:
System
System.Management
Here is the code showing each ID return separately:
Code:
public class HWID
{
static string hwid_str;
static string ram;
static string ramid;
static string cpu;
static string mobo;
static string moboid;
static string cpuid;
static string hdd = null;
static string hddid;
static string hddstr;
static void Main(string[] args)
{
ramID();
cpuID();
moboID();
hddID();
hwid_str = ramid + "-" + cpuid + "-" + moboid + "-" + hddstr;
Console.WriteLine("Unique HWID: " + hwid_str);
Console.ReadKey();
}
static void cpuID()
{
ManagementObjectCollection mbsList = null;
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
mbsList = mbs.Get();
foreach (ManagementObject mo in mbsList)
{
cpu = mo["ProcessorID"].ToString();
cpuid = cpu.Substring(cpu.Length - 10);
}
}
static void moboID()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
ManagementObjectCollection moc = mos.Get();
foreach (ManagementObject mo in moc)
{
mobo = (string)mo["SerialNumber"];
moboid = mobo.Substring(mobo.Length - 10);
}
}
static string hddID()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
foreach (ManagementObject wmi_HD in searcher.Get())
{
if (wmi_HD["SerialNumber"] != null)
hddid = (string)wmi_HD["SerialNumber"].ToString();
hddstr = hddid.Substring(hddid.Length - 14);
}
return string.Empty;
}
static void ramID()
{
ManagementObjectSearcher mor = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory");
ManagementObjectCollection mok = mor.Get();
foreach (ManagementObject morm in mok)
{
ram = (string)morm["PartNumber"];
ramid = ram.Substring(ram.Length - 10);
}
}
}
Enjoy