答案 0 :(得分: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;
}
答案 1 :(得分:0)
rtry this:
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/
答案 2 :(得分:0)
代码项目中的示例:
Read, write and delete from registry with C#
All (you wanted to know) about the Registry with C#, Part 1 of 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();