Jun 14, 2011 04:35 AM
(This post was last modified: Aug 17, 2011 12:31 AM by ubbelol.)
Here's a neat function I made to retrieve an unique ID for every computer.. The only difference from most of the others is that this doesn't use WMI to retrieve it.
Here you go:
APIs & struct:
Here you go:
Code
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)).Replace("-", null);
for(int i = 0;i < 64;i++)
if (i % 16 == 0 && i != 0)
outStr = outStr.Insert(i, "-");
return outStr;
}APIs & struct:
Code
[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;
}
Probably coding some useless shit.



![[Image: 17e2e9d7a337a869d7aa679ffb26b8c3.png]](https://gyazo.com/17e2e9d7a337a869d7aa679ffb26b8c3.png)
![[Image: 2e0b9ca4a3663f824dccb682d6da5f89.png]](https://gyazo.com/2e0b9ca4a3663f824dccb682d6da5f89.png)
