让Windows细节,如产品密钥,域名,用户名等。 [英] Get windows details like product key, domain name, user name, etc.
问题描述
像OS我怎样才能得到操作系统的详细信息序列号
(OS产品密钥),用户域名
, 用户名
和 PC全名
?
什么是最好的方式和最佳的方式来得到它?
How can I get Operating system details like OS Serial Number
(OS Product key), User Domain Name
,User Name
and PC Full Name
?
What is the best way and optimal way to get it?
推荐答案
退房(静态)<一href="http://msdn.microsoft.com/en-us/library/system.environment.aspx"><$c$c>System.Environment$c$c>类。
System.Environment
Check out the (static) System.Environment
class.
它有一个<一个属性href="http://msdn.microsoft.com/en-us/library/system.environment.machinename.aspx"><$c$c>MachineName$c$c>, <一href="http://msdn.microsoft.com/en-us/library/system.environment.userdomainname.aspx"><$c$c>UserDomainName$c$c>,和<一href="http://msdn.microsoft.com/en-us/library/system.environment.username.aspx"><$c$c>UserName$c$c>.
如果你正在寻找BIOS中的序列号(或很多其他硬件上的信息),你可以尝试<一href="http://msdn.microsoft.com/en-us/library/system.management.aspx"><$c$c>System.Management$c$c>命名空间,特别是<一个href="http://msdn.microsoft.com/en-us/library/system.management.selectquery.aspx"><$c$c>SelectQuery$c$c>和<一href="http://msdn.microsoft.com/en-us/library/system.management.managementobjectsearcher.aspx"><$c$c>ManagementObjectSearcher$c$c>.
If you're looking for the BIOS serial number (or lots of info on other hardware) you might try the System.Management
namespace, specifically SelectQuery
and ManagementObjectSearcher
.
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_Processor 或他人获取关于机器的其他信息。 COM / EN-US /库/ aa389273.aspx> MSDN 。这是使用 WMI
通过<一HREF =http://en.wikipedia.org/wiki/WQL> WQL
。
You can get other info about the machine by querying, for example, on Win32_Processor
or others as listed on MSDN. This is using WMI
via WQL
.
有关操作系统的序列号,在Windows的许多版本,它是在 HKEY_LOCAL_MACHINE \ SOFTWARE \微软\的Windows NT \ CURRENTVERSION \ DigitalProductId
存储在注册表中,但它在一些连接codeD的形式,并且需要以德codeD以获得产品密钥。
For an OS serial number, in many versions of Windows, it is stored in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
, however it is in some encoded form and needs to be decoded to get the product key.
您可以使用下面的方法去code这个值,发现这里一>(但稍微修改为清楚起见)。
You can use the following method to decode this value, found here (but slightly modified for clarity).
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 / 它使用上面给出的方法并提供有关设备的某些附加信息。
Alternatively, I found an open source c# project that supposedly can extract the product key for any version of windows: http://wpkf.codeplex.com/ It uses the method given above and provides some additional information about the machine.
这篇关于让Windows细节,如产品密钥,域名,用户名等。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!