开发者

The most simple way to get the value of a registry key

开发者 https://www.devze.com 2023-02-20 05:44 出处:网络
Is it possible to get a value of a \"registry key\" without parsing the path to the registry? What I am actually looking for is a one liner command to get the value of a key like:

Is it possible to get a value of a "registry key" without parsing the path to the registry?

What I am actually looking for is a one liner command to get the value of a key like:

object value = Registry.GetValue("path");

The "path", for example, is: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Install

The Install key is actually the value.

Currently, I am doing this:

object value = Registry.GetValue("HKEY_LOCA开发者_如何转开发L_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", "Install", null);

So question, is it possible to get the value of a registry key without parsing the path?

Thanks!


You don't need to parse the key name and value name yourself, the Path class can do it for you:

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


You can use Registry.LocalMachine for HKLM. You can get some ideas here http://www.csharphelp.com/2007/01/registry-ins-and-outs-using-c/ :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消