【问题标题】:Get windows details like product key, domain name, user name, etc.获取 Windows 详细信息,如产品密钥、域名、用户名等。
【发布时间】:2012-12-01 00:24:10
【问题描述】:

如何获取操作系统详细信息,例如 OS Serial Number(OS 产品密钥)、User Domain NameUser NamePC Full Name? 获得它的最佳方式和最佳方式是什么?

【问题讨论】:

  • 您使用的 Windows 版本是什么?
  • 您要获取哪个“序列号”? Windows、主板等?
  • 您的名字是用于从 Windows 中提取产品密钥的 codeplex 项目的字谜 - wpkf.codeplex.com 是否只是巧合?无论如何,正如我在更新的答案中提到的那样,它可能会对您有所帮助,尤其是 .NET 和开源。
  • 只是巧合:)

标签: c# .net windows


【解决方案1】:

系统.环境

查看(静态)System.Environment 类。

它具有MachineNameUserDomainNameUserName 的属性。

系统管理

如果您正在寻找 BIOS 序列号(或其他硬件上的大量信息),您可以尝试使用 System.Management 命名空间,特别是 SelectQueryManagementObjectSearcher

var query = new SelectQuery("select * from Win32_Bios");
var search = new ManagementObjectSearcher(query);
foreach (ManagementBaseObject item in search.Get())
{
    string serial = item["SerialNumber"] as string;
    if (serial != null)
        return serial;
}

您可以通过查询获得有关机器的其他信息,例如,Win32_ProcessorMSDN 上列出的其他信息。这是通过WQL 使用WMI

通过注册表的 Windows 产品密钥

对于操作系统序列号,在许多版本的 Windows 中,它存储在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId 的注册表中,但它是某种编码形式,需要解码才能获得产品密钥。

您可以使用下面的方法来解码这个值,找到here(但为了清晰起见稍作修改)。

public string DecodeProductKey(byte[] digitalProductId)
{
    // Possible alpha-numeric characters in product key.
    const string digits = "BCDFGHJKMPQRTVWXY2346789";
    // Length of decoded product key in byte-form. Each byte represents 2 chars.
    const int decodeStringLength = 15;
    // Decoded product key is of length 29
    char[] decodedChars = new char[29];

    // Extract encoded product key from bytes [52,67]
    List<byte> hexPid = new List<byte>();
    for (int i = 52; i <= 67; i++)
    {
        hexPid.Add(digitalProductId[i]);
    }

    // Decode characters
    for (int i = decodedChars.Length - 1; i >= 0; i--)
    {
        // Every sixth char is a separator.
        if ((i + 1) % 6 == 0)
        {
            decodedChars[i] = '-';
        }
        else
        {
            // Do the actual decoding.
            int digitMapIndex = 0;
            for (int j = decodeStringLength - 1; j >= 0; j--)
            {
                int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
                hexPid[j] = (byte)(byteValue / 24);
                digitMapIndex = byteValue % 24;
                decodedChars[i] = digits[digitMapIndex];
            }
        }
    }

    return new string(decodedChars);
}

另外,我发现了一个开源 c# 项目,据说可以为任何版本的 windows 提取产品密钥:http://wpkf.codeplex.com/ 它使用上面给出的方法并提供有关机器的一些附加信息。

【讨论】:

    【解决方案2】:

    你试过Systeminformation class吗,它提供了很多关于当前系统环境的信息,看看MSDN网站上的例子。它具有以下属性:

    ComputerName, UserDomianName, UserName ...等

    【讨论】:

    • 请注意,这取决于 WinForms。
    • SystemInformation 类,唯一有用的信息是你说的那 3 个(ComputerName、UserDomianName、UserName)和屏幕分辨率,没有别的,Windows 产品密钥来自这个?甚至没有接近它。
    【解决方案3】:

    您需要使用IPGlobalProperties.GetIPGlobalProperties Method 获取网络相关信息:

    var conInfo = IPGlobalProperties.GetIPGlobalProperties();
    Console.WriteLine(conInfo.HostName);
    Console.WriteLine(conInfo.DomainName);
    ...
    

    机器名称使用Environment.MachineName Property:

    Console.WriteLine(System.Environment.MachineName);
    

    【讨论】:

    • 不行,这种方法连IP地址都无法获取,OP正在要求Windows Key。
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多