4

Serial NumberOS (OS プロダクト キー)、、、User Domain NameなどUser Nameのオペレーティング システムの詳細を取得するにはどうすればよいPC Full Nameですか? それを取得するための最良の方法と最適な方法は何ですか?

4

3 に答える 3

9

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を使用しています。WMIWQL

レジストリを介した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/上記の方法を使用し、マシンに関する追加情報を提供します。

于 2012-12-13T06:40:24.297 に答える
-1

ネットワーク関連の情報を取得するには、 IPGlobalProperties.GetIPGlobalPropertiesメソッドを使用する必要があります。

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

マシン名には、Environment.MachineNameプロパティを使用します。

Console.WriteLine(System.Environment.MachineName);
于 2012-12-13T06:40:01.727 に答える
-1

現在のシステム環境に関する多くの情報を提供するSysteminformationクラスを試してみましたか?MSDNサイトの例をご覧ください。次のプロパティがあります。

ComputerNameUserDomianNameUserName ... etc

于 2012-12-13T06:40:15.097 に答える