473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

C# registry problem

I'm writing an executable that will either give or take away access to the TaskManager. The problem is some of the computers on my LAN don't have the subkey. I tried to create it but I got this message:

An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Cannot write to the registry key.

Here is my source:
RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAcc ess, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");

//Get the names of the subkeys to determine if the subkey "System" already exists.
RegistryKey temp = Registry.CurrentUser.OpenSubKey("Software\\Microso ft\\Windows\\CurrentVersion\\Policies");
foreach(string subKeyName in temp.GetSubKeyNames())
{
if(subKeyName == "System")
{
RegistryKey nrk = temp.OpenSubKey("System" ,true);
nrk.SetValue("DisableTaskMgr","1");
nrk.Close();
}
else
{
RegistryPermission P = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");
---------------->>> RegistryKey nrk = temp.CreateSubKey("System");
nrk.SetValue("DisableTaskMgr","1");
nrk.Close();
}

As you can see I should theoretically have access because I set the permissions with:
RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAcc ess, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");

Any help would be appreciated.

--------------------------------
From: Sean Riker

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>8UhjH6UAM0aUzD4ONWEMlQ==</Id>
Nov 22 '05 #1
1 2912
Sean,
RegistryKey temp = Registry.CurrentUser.OpenSubKey("Software\\Microso ft\\Windows\\CurrentVersion\\Policies");
You have to open this with write access (pass true as the second
parameter) to create subkeys.

As you can see I should theoretically have access because I set the permissions with:
RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAcc ess, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");


No, this line of code doesn't set any permissions. In fact, it doesn't
do much at all since you never use the f object.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rdavis7408 | last post by:
I have a database that has a form that opens a report using date parameters. I have been using it for six months and last week I began to get the following Error Message: "File sharing lock...
21
by: Kevin Swanson | last post by:
I'm attempting some remote registry manipulation via C#. I've written a test app to simply grab a specified key from a specified hive on a specified machine. The call to OpenSubKey is throwing...
2
by: Daniel Bass | last post by:
I've found this article on how to get ASP.Net to read/write from the server's registry, but it got heavily critted as being something that you should not do... ...
8
by: Al Kaufman | last post by:
I have a simple console app that uses: regSubKey = <some registry key> Dim reg As RegistryKey = Registry.ClassesRoot.OpenSubKey(regSubKey) Dim path As String path = CStr(reg.GetValue(""))
17
by: Sam | last post by:
Hi all If I only want to store screen location and size of my application in Windows Registry, which of the keys should I store this info? A sample code is greatly appreciated. Thank you ...
3
by: Dylan Parry | last post by:
Hi folks, I've just got a new machine at work, so I've spent all day copying across all of my work from my old machine. Now I've come across a problem that I've never seen before. I now get...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
3
by: Aussie Rules | last post by:
Hi, I want to store some data in the registry, however I have not been able to do this, and think my logic maybe flawed. Firstly I try to open the registry and read in any existing values....
6
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList...
0
by: tmsprowl | last post by:
Greetings! I was wondering if someone could help me with a problem I'm having. My department is just one of many within my organization. My organization has control over the network domain,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.