Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default value of key from the registry

Tags:

c#

.net

registry

I am trying get the (Default) key value from the HKEY_CLASSES_ROOT and the code snippet I tried is as below,

using (var key = Registry.ClassesRoot.OpenSubKey(@"Excel.Application\\CurVer"))
{
    var defvalue = key?.GetValue("(Default)");
    if (defvalue != null)
    {
    }
}

Always the defvalue is coming as null. I am not able trace out what mistake I am doing.

Could anyone please help me to resolve this.

like image 255
Siva Avatar asked Jul 27 '17 11:07

Siva


People also ask

What is default value of registry key?

What used to be called simply “the value of a registry key” (for since there was only one, there was no need to give it a name) now goes by the special name the default value: It's the value whose name is null.

How do I read registry values?

Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.

What are the different types of registry values?

The possible types for a registry value are: string (REG_SZ or REG_MULTI_SZ), expandable string (REG_EXPAND_SZ), integer (REG_DWORD) and binary (REG_BINARY).


1 Answers

Instead of using "(Default)", you'll need to use an empty string ("").

using (var key = Registry.ClassesRoot.OpenSubKey(@"Excel.Application\\CurVer"))
{
    var defvalue = key?.GetValue("");
    if (defvalue != null)
    {
    }
}
like image 67
Obi Avatar answered Oct 11 '22 18:10

Obi