By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

writing new value to registry key

P: n/a
Hi
I have accessed registry key where system path is stored:

RegistryKey myKey =
Registry.LocalMachine.OpenSubKey("System\\CurrentC ontrolSet\\Control\\Sessi*on

Manager\\Environment");
Then i'am trying to change the value:
if (myKey != null)
{
object val = myKey.GetValue("Path");
RegistryValueKind rvk = myKey.GetValueKind("Path");

val = dir + ";" + val;
myKey.DeleteValue("Path");
myKey.SetValue("Path", val);
return;
}
OpenSubKey returns key read only. I dunno how to set access to this
regkey such that is would be possible to write to it.
How to change privilages to force program to write new val to the reg?
Thanks for any sugestions
Piotr Kolodziej

Sep 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello:
Yoy have and overloaded method for this, just passing a boolean
indicating if you want write acces to the key. Here is an example:

try {
RegistryKey regKey = Registry.LocalMachine;
regKey =
regKey.OpenSubKey(@"Software\Microsoft\Windows\Cur rentVersion\Run",
true); // This last bool values specify write acces to registry
regKey.SetValue("SomeValue);
regKey.Close();
}
catch (SecurityException) {
throw new InstallException("You need administrator
rights to install this program.");
}

Happy coding!!

Oscar Acosta
Piotrekk wrote:
Hi
I have accessed registry key where system path is stored:

RegistryKey myKey =
Registry.LocalMachine.OpenSubKey("System\\CurrentC ontrolSet\\Control\\Sessi*on

Manager\\Environment");
Then i'am trying to change the value:
if (myKey != null)
{
object val = myKey.GetValue("Path");
RegistryValueKind rvk = myKey.GetValueKind("Path");

val = dir + ";" + val;
myKey.DeleteValue("Path");
myKey.SetValue("Path", val);
return;
}
OpenSubKey returns key read only. I dunno how to set access to this
regkey such that is would be possible to write to it.
How to change privilages to force program to write new val to the reg?
Thanks for any sugestions
Piotr Kolodziej
Sep 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.