Solved

Changing a registry value in C#

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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