Hi :) I'm writing a C# application and need to get the HWID code for the computer the code is running on. Since this is a console, i need to figure out a way to find the HWID for the CPU, motherboard and HDD, without using the the WMI. Since the system.management is not available on linux, i need it without using that. is it possible to find the HWID without the WMI? Or could i find a way to use the WMI for linux to find the HWID?
Is it possible in C# to do this? I would appreciate if anyone told me how, or pointed me in the right direction to get started. thank you all!
Try this link, not sure if it will work on linux though.
Updated
private string GetUID()
{
StringBuilder strB = new StringBuilder();
Guid G = new Guid(); HidD_GetHidGuid(ref G);
strB.Append(Convert.ToString(G));
IntPtr lHWInfoPtr = Marshal.AllocHGlobal(123); HWProfile lProfile = new HWProfile();
Marshal.StructureToPtr(lProfile, lHWInfoPtr, false);
if (GetCurrentHwProfile(lHWInfoPtr))
{
Marshal.PtrToStructure(lHWInfoPtr, lProfile);
strB.Append(lProfile.szHwProfileGuid.Trim(new char[] { '{', '}' }));
}
Marshal.FreeHGlobal(lHWInfoPtr);
SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider();
byte[] B = Encoding.Default.GetBytes(strB.ToString());
string outStr = BitConverter.ToString(SHA256.ComputeHash(B)).Repla ce("-", null);
for(int i = 0;i < 64; i++)
{
if (i % 16 == 0 && i != 0)
outStr = outStr.Insert(i, "-");
}
return (outStr);
}
[DllImport("hid.dll")]
private static extern void HidD_GetHidGuid(ref Guid GUID);
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool GetCurrentHwProfile(IntPtr fProfile);
[StructLayout(LayoutKind.Sequential)]
class HWProfile
{
public Int32 dwDockInfo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 39)]
public string szHwProfileGuid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szHwProfileName;
}