Solved

C# Registry Permission can't Write to Registry

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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