I want to configure my C# Windows Form application such that before running the application, it identifies match the current machine's hard-drive serial number. If the hard-drive serial number matches with the configured serial number, it runs the application otherwise do nothing.
I want to make it run only on a single machine to prevent redistribution of the application because this is a custom application developed only for a client with some special requirements.
The following code gets the current machine's hard-drive serial number, model and interface type.
ManagementObjectSearcher moSearcher = new ManagementObjectSearcher("select * from Win32_DiskDrive");
foreach (ManagementObject wmi_HDD in moSearcher.Get())
{
HardDrive hdd = new HardDrive();
hdd.Model = wmi_HDD["Model"].ToString();
hdd.SerialNo = wmi_HDD["SerialNumber"].ToString();
hdd.Type = wmi_HDD["InterfaceType"].ToString();
HDDArrayList.Add(wmi_HDD);
txtHDDModel.Text = hdd.Model;
txtHDDSerialNo.Text = hdd.SerialNo;
txtHDDType.Text = hdd.Type;
}
This code is currently running on a button click. I want it to run before the main method it can get the current machine hard-drive serial number and compares it with my target serial number (the one I want to allow).
Is there any better approach for this as well as for the comparison process?