Solved

C# Registry Permission can't Write to Registry

Posted on 2006-07-19
5
5,225 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
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

17 Experts available now in Live!

Get 1:1 Help Now