Nasser Hamdan
asked on
Change Registry Value using C#
Hi,
I have desktop c# application, and when this application main frm loads i want to update some registry value to null ...
the regsitry value resided on:
HKEY_CURRENT_USER\AppEvent s\Schemes\ Apps\.Defa ult\.Defau lt\.Curren t
This key have default vallue as (%SystemRoot%\media\Window s XP Ding.wav)
And i just want to replace it with null ! i tried this and didnt work !
I have desktop c# application, and when this application main frm loads i want to update some registry value to null ...
the regsitry value resided on:
HKEY_CURRENT_USER\AppEvent
This key have default vallue as (%SystemRoot%\media\Window
And i just want to replace it with null ! i tried this and didnt work !
RegistryKey rkHKLM = Registry.CurrentUser; ;
RegistryKey rkRun;
rkRun =
rkHKLM.OpenSubKey(@"HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\.Default\.Current", true);
rkRun.SetValue("Default", "");
Registry.CurrentUser.Flush();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Fernando,
I tried the solution as well read the article,, and tried what is suggesting, but i faced same problem which is exception saying: Object refrence not set to an instance of object.
here is the code again after modify it:
I tried the solution as well read the article,, and tried what is suggesting, but i faced same problem which is exception saying: Object refrence not set to an instance of object.
here is the code again after modify it:
RegistryKey rkHKLM = Registry.CurrentUser;
RegistryKey rkRun;
rkRun =
rkHKLM.OpenSubKey(@"HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\.Default\.Current", true);
rkRun.SetValue(null, "");
Registry.CurrentUser.Flush();
ASKER
Thanks alot ... i cant believe that it was so easy and i spent 4 hours try to figure it out :(
As per the documentation:
Since many values can be stored in each key in the registry, the name parameter specifies the particular value you want to manipulate. To set the default value for a particular registrykey, name can be set to either a null reference (Nothing in Visual Basic), or the empty string ("").
http://msdn2.microsoft.com/en-us/library/microsoft.win32.registrykey.setvalue(VS.71).aspx
So change this:
rkRun.SetValue("Default", "");
To this:
rkRun.SetValue("", "");
or this:
rkRun.SetValue(null, "");
Fernando