PC Review


Reply
Thread Tools Rate Thread

C# registry problem

 
 
Sean Riker via .NET 247
Guest
Posts: n/a
 
      6th Jun 2004
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.AllAccess, "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\\Microsoft\\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.AllAccess, "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>
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      7th Jun 2004
Sean,

>RegistryKey temp = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\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.AllAccess, "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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Registry problem =?Utf-8?B?aG9rdW4gbGVl?= Windows XP Help 4 2nd Jun 2006 10:18 AM
Registry problem? =?Utf-8?B?U3RhbiBUaGUgTWFu?= Windows XP General 2 21st Apr 2006 04:54 AM
XP Registry Problem HEP! =?Utf-8?B?anN0YXJ3dA==?= Windows XP General 2 11th Jan 2005 10:01 PM
XP registry problem Glynne Windows XP General 7 14th May 2004 01:56 AM
Registry Problem Saine Windows XP General 3 29th Oct 2003 07:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:29 PM.