Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Get Unique ID (Like HWID) Not using WMI

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:

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.
Nice work man

Thanks a lot :)
Nice job dude ;)
Added it to my thread: https://hackforums.net/showthread.php?tid=1350578
(Jun 14, 2011 04:57 AM)ra1d Wrote:  Nice job dude ;)
Added it to my thread: https://hackforums.net/showthread.php?tid=1350578

Cool. :) Don't know how much people will learn that much from this but okay.
Probably coding some useless shit.
Thanks a lot! On average this is 100ms faster then HWID (in my own case), tested in my program DataVault.

Thought I should post some pictures:
HWID
[Image: 17e2e9d7a337a869d7aa679ffb26b8c3.png]
UID
[Image: 2e0b9ca4a3663f824dccb682d6da5f89.png]
very nice man....thanks a lot
Don't use P/Invoke, it requires some ... uhm specific permissions.😅
(Jun 16, 2011 12:31 AM)tflo Wrote:  Thanks a lot! On average this is 100ms faster then HWID (in my own case), tested in my program DataVault.

Thought I should post some pictures:
HWID
[Image: 17e2e9d7a337a869d7aa679ffb26b8c3.png]
UID
[Image: 2e0b9ca4a3663f824dccb682d6da5f89.png]

Well WMI is pretty slow. :P
Probably coding some useless shit.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by LaTortueJun 11, 2020 10:05 AM 3 248 Jun 11, 2020 10:05 AM
Last Post: LaTortue
[C#] by chrizatorFeb 4, 2018 09:23 AM 12 556 Feb 4, 2018 09:23 AM
Last Post: chrizator
[C#] by VeloOct 15, 2017 09:26 PM 17 931 Oct 15, 2017 09:26 PM
Last Post: gigajew