Solved

Changing a registry value in C#

Posted on 2006-11-29
4
238 Views
Last Modified: 2010-04-16
I want to change the value of a registry key from 0x00000003 to 0x0000000. Here is the code I wrote to do it that doesnt work because rk is always null for some reason, I don't get it.

  RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"My Computer\HKEY_CURRENT_USER\Software\Microsoft\Visio\Addins\mass.Connect");
           if (rk != null)
           {
               rk.SetValue("LoadBehavior", 0);
               rk.Close();
           }

Whats wrong here?
0
Comment
Question by:npl77
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 18041014
It should be:

RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Visio\Addins\mass.Connect");
           if (rk != null)
           {
               rk.SetValue("LoadBehavior", 0);
               rk.Close();
           }


0
 

Author Comment

by:npl77
ID: 18041091
now it says i cant write to registry key. How I change that?
0
 

Author Comment

by:npl77
ID: 18041097
UnAuthorizedAccessException
0
 
LVL 14

Expert Comment

by:existenz2
ID: 18041110
You most likely don't have the rights to write to the registry. Is that correct?

Else give this a try:
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Visio\Addins\mass.Connect");

But that most likely won't work and it prolly is a registry security issue.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now