Solved

Changing a registry value in C#

Posted on 2006-11-29
4
237 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

16 Experts available now in Live!

Get 1:1 Help Now