forked from davcs86/csharp-uhwid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsId.cs
37 lines (32 loc) · 1.29 KB
/
WindowsId.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Management;
using System.Security.Cryptography;
using System.Text;
namespace UHWID
{
internal class WindowsId
{
public static string GetWindowsId()
{
var windowsInfo = "";
var managClass = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
var managCollec = managClass.Get();
var is64Bits = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
foreach (var o in managCollec)
{
var managObj = (ManagementObject) o;
windowsInfo = managObj.Properties["Caption"].Value + Environment.UserName + (string) managObj.Properties["Version"].Value;
break;
}
windowsInfo = windowsInfo.Replace(" ", "");
windowsInfo = windowsInfo.Replace("Windows", "");
windowsInfo = windowsInfo.Replace("windows", "");
windowsInfo += (is64Bits) ? " 64bit" : " 32bit";
//md5 hash of the windows version
var md5Hasher = MD5.Create();
var wi = md5Hasher.ComputeHash(Encoding.Default.GetBytes(windowsInfo));
var wiHex = BitConverter.ToString(wi).Replace("-", "");
return wiHex;
}
}
}