2

グーグルは今日私を助けていないので、私はあなたの助けが必要です。レジストリから値を読み取るための可能な方法はありますか?この場所の例->HKEY_LOCAL_MACHINE>SOFTWARE>MyKey列はテストキーです

4

3 に答える 3

11

64ビット+32ビット

   using Microsoft.Win32;
    public static string GetRegistry()
    {
        string registryValue = string.Empty;
        RegistryKey localKey = null;
        if (Environment.Is64BitOperatingSystem)
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
        }
        else
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
        }

        try
        {
            localKey = localKey.OpenSubKey(@"Software\\MyKey");
            registryValue = localKey.GetValue("TestKey").ToString();
        }
        catch (NullReferenceException nre)
        {

        }
        return registryValue;
    }
于 2012-10-23T12:55:43.760 に答える
0

これを試してみてください:

static object GetRegistryValue(string fullPath, object defaultValue)
{
    string keyName = Path.GetDirectoryName(fullPath);
    string valueName = Path.GetFileName(fullPath);
    return Registry.GetValue(keyName, valueName, defaultValue);
}

Registry.LocalMachine または、このhttp://www.csharphelp.com/2007/01/registry-ins-and-outs-using-c/を使用することもできます。

于 2012-10-23T12:54:25.327 に答える
0

コードプロジェクトの例:

C#を使用してレジストリの読み取り、書き込み、および削除を行う

C#を使用したレジストリに関するすべて(知りたい)、パート1/2

using Microsoft.Win32;
...

RegistryKey masterKey = Registry.LocalMachine.CreateSubKey(
            "SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
    Console.WriteLine ("Null Masterkey!");
}
else
{
    Console.WriteLine ("MyKey = {0}", masterKey.GetValue ("MyKey"));
}
masterKey.Close();
于 2012-10-23T12:55:08.783 に答える