Solved

C# Registry Permission can't Write to Registry

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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