Serial Number
OS (OS プロダクト キー)、、、User Domain Name
などUser Name
のオペレーティング システムの詳細を取得するにはどうすればよいPC Full Name
ですか? それを取得するための最良の方法と最適な方法は何ですか?
3 に答える
System.Environment
System.Environment
(静的)クラスをチェックしてください。
MachineName
、、、UserDomainName
およびのプロパティがありUserName
ます。
システムマネジメント
BIOSのシリアル番号(または他のハードウェアに関する多くの情報)を探している場合は、System.Management
名前空間、具体的SelectQuery
にはとを試してみてください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;
}
たとえば、MSDNWin32_Processor
にリストされている他の人にクエリを実行することで、マシンに関する他の情報を取得できます。これはviaを使用しています。WMI
WQL
レジストリを介したWindowsプロダクトキー
OSのシリアル番号の場合、Windowsの多くのバージョンでは、のレジストリに保存されますがHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
、エンコードされた形式であるため、プロダクトキーを取得するにはデコードする必要があります。
次の方法を使用して、ここにあるこの値をデコードできます(ただし、わかりやすくするために少し変更しました)。
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);
}
または、任意のバージョンのWindowsのプロダクトキーを抽出できると思われるオープンソースのc#プロジェクトを見つけました。http ://wpkf.codeplex.com/上記の方法を使用し、マシンに関する追加情報を提供します。
ネットワーク関連の情報を取得するには、 IPGlobalProperties.GetIPGlobalPropertiesメソッドを使用する必要があります。
var conInfo = IPGlobalProperties.GetIPGlobalProperties();
Console.WriteLine(conInfo.HostName);
Console.WriteLine(conInfo.DomainName);
...
マシン名には、Environment.MachineNameプロパティを使用します。
Console.WriteLine(System.Environment.MachineName);
現在のシステム環境に関する多くの情報を提供するSysteminformationクラスを試してみましたか?MSDNサイトの例をご覧ください。次のプロパティがあります。
ComputerName、UserDomianName、UserName ... etc