Solved

C# Registry Permission can't Write to Registry

Posted on 2006-07-19
5
5,287 Views
Last Modified: 2008-12-16
I'm trying to make a program that will write to a particular registry Key that "Everybody" doesn't have full control over.

Here's the basic Gyst of the code:
RegistryKey key2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\FTDIBUS\\VID_0403+PID_6001+5&138461b1&0&1\\0000", true);

This particular key inherits its security settings from the Enum Key.

If I run the same line without the true on the end, it goes past this line, but hangs whenever I try to write to the key.

I can successfully write to other keys/values with no problem.

Here's the kicker. If I go into RegEdit, I can set the permissions manually so that Everyone has Full Access to this key,  the program works without a hitch.

Currently only SYSTEM has Full Access.

I plan on deploying this to many computers, so I need a way for the program to Change the Permissions for that Key. I'm assuming if the person running the program has Admin Access, then I should be able to accomplish this.

I have tried inserting:
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, Write=@"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum")]

at the beginning, but that doesn't do anything.

I've fooled with with RegistryAccessRules, and I've made a Rule that will accomplish what I want, but I have no earthly idea how to apply that rule to the registry key if it isn't open in write mode (true at the end);

I would greatly appreciate any help at all with this.
0
Comment
Question by:dkattan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17141470
Your program cannot take control of the registry, it has to be granted control to write to the registry.

What exactly do you need to change with this apparent PCI device entry?  Is there an API interface that can change this without having to hack the registry?

Bob
0
 
LVL 2

Assisted Solution

by:NewMom2Brandon
NewMom2Brandon earned 250 total points
ID: 17156189
OpenSubKey opens it as read only.

using System;
// it's required for reading/writing into the registry:
using Microsoft.Win32;      
using System.Windows.Forms;


public bool Write(string KeyName, object Value)
{
    try
    {
        // Setting
        RegistryKey rk = baseRegistryKey ;
        // I have to use CreateSubKey
        // (create or open it if already exits),
        // 'cause OpenSubKey open a subKey as read-only
        RegistryKey sk1 = rk.CreateSubKey(subKey);
        // Save the value
        sk1.SetValue(KeyName.ToUpper(), Value);

        return true;
    }
    catch (Exception e)
    {
        ShowErrorMessage(e, "Writing registry " + KeyName.ToUpper());
        return false;
    }
}
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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