I have some C# code I am using to delete a subkey and its tree from the
registry however I am running into some issues.
At first, I was using the Registry.LocalM achine.DeleteSu bKeyTree method and
passing it a string like this:
SubKeyBase = @"SYSTEM\Curren tControlSet\Enu m\";
Registry.LocalM achine.DeleteSu bKeyTree(SubKey Base + InstanceID);
The variable InstanceID had something like this in it:
USB\VID_xxxx&PI D_xxxx\xxxxxxxx xxxxx
This is the instance ID of a USB device and it correlates exactly to the
information stored about the device in the registry. By appending these two,
I came up with the path to the registry key/tree that I wanted to delete:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\E num\USB\VID_xxx x&PID_xxxx\xxxx xxxxxxxxx
Using this approach, I was getting an ArgumentExcepti on saying that the key
does not exist, however I could open up regedit and the key was there and I
could delete it manually if I wanted without a problem. So since I couldn't
figure out what was going on, I decided to use OpenSubKey to open the path
defined by SubKeyBase (ie. "SYSTEM\Current ControlSet\Enum ") and then use that
RegistryKey object to delete the key/tree I needed and see if I got any
different result.
RegistryKey rk = Registry.LocalM achine.OpenSubK ey(SubKeyBase, true);
(The 2nd argument with a value of true is to indicate I need write access)
Well, this statement is throwing a SecurityExcepti on even though I can
manually open up regedit and delete the key. I am a fairly new to the .NET
framework so I am not sure what I need to give my application the security
clearance to perform these operations. I was under the impression that it
automatically inherited the security profile of the user running the
application but it seems this is not the case.
Any help is greatly appreciated!
Regards,
David K 2 5269
By chance, are you using a 64 bit OS? Something similar drove me crazy
until I read about registry virtualization under such OSs.
"David K" <Da****@discuss ions.microsoft. comwrote in message
news:B5******** *************** ***********@mic rosoft.com...
>I have some C# code I am using to delete a subkey and its tree from the
registry however I am running into some issues.
At first, I was using the Registry.LocalM achine.DeleteSu bKeyTree method
and
passing it a string like this:
SubKeyBase = @"SYSTEM\Curren tControlSet\Enu m\";
Registry.LocalM achine.DeleteSu bKeyTree(SubKey Base + InstanceID);
The variable InstanceID had something like this in it:
USB\VID_xxxx&PI D_xxxx\xxxxxxxx xxxxx
This is the instance ID of a USB device and it correlates exactly to the
information stored about the device in the registry. By appending these
two,
I came up with the path to the registry key/tree that I wanted to delete:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\E num\USB\VID_xxx x&PID_xxxx\xxxx xxxxxxxxx
Using this approach, I was getting an ArgumentExcepti on saying that the
key
does not exist, however I could open up regedit and the key was there and
I
could delete it manually if I wanted without a problem. So since I
couldn't
figure out what was going on, I decided to use OpenSubKey to open the path
defined by SubKeyBase (ie. "SYSTEM\Current ControlSet\Enum ") and then use
that
RegistryKey object to delete the key/tree I needed and see if I got any
different result.
RegistryKey rk = Registry.LocalM achine.OpenSubK ey(SubKeyBase, true);
(The 2nd argument with a value of true is to indicate I need write access)
Well, this statement is throwing a SecurityExcepti on even though I can
manually open up regedit and delete the key. I am a fairly new to the
.NET
framework so I am not sure what I need to give my application the security
clearance to perform these operations. I was under the impression that it
automatically inherited the security profile of the user running the
application but it seems this is not the case.
Any help is greatly appreciated!
Regards,
David K
Sorry, I entirely forgot to mention the OS it's on. This is under Windows XP
Pro, so not a 64-bit OS. Any other ideas?
"Family Tree Mike" wrote:
By chance, are you using a 64 bit OS? Something similar drove me crazy
until I read about registry virtualization under such OSs.
"David K" <Da****@discuss ions.microsoft. comwrote in message
news:B5******** *************** ***********@mic rosoft.com...
I have some C# code I am using to delete a subkey and its tree from the
registry however I am running into some issues.
At first, I was using the Registry.LocalM achine.DeleteSu bKeyTree method
and
passing it a string like this:
SubKeyBase = @"SYSTEM\Curren tControlSet\Enu m\";
Registry.LocalM achine.DeleteSu bKeyTree(SubKey Base + InstanceID);
The variable InstanceID had something like this in it:
USB\VID_xxxx&PI D_xxxx\xxxxxxxx xxxxx
This is the instance ID of a USB device and it correlates exactly to the
information stored about the device in the registry. By appending these
two,
I came up with the path to the registry key/tree that I wanted to delete:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\E num\USB\VID_xxx x&PID_xxxx\xxxx xxxxxxxxx
Using this approach, I was getting an ArgumentExcepti on saying that the
key
does not exist, however I could open up regedit and the key was there and
I
could delete it manually if I wanted without a problem. So since I
couldn't
figure out what was going on, I decided to use OpenSubKey to open the path
defined by SubKeyBase (ie. "SYSTEM\Current ControlSet\Enum ") and then use
that
RegistryKey object to delete the key/tree I needed and see if I got any
different result.
RegistryKey rk = Registry.LocalM achine.OpenSubK ey(SubKeyBase, true);
(The 2nd argument with a value of true is to indicate I need write access)
Well, this statement is throwing a SecurityExcepti on even though I can
manually open up regedit and delete the key. I am a fairly new to the
.NET
framework so I am not sure what I need to give my application the security
clearance to perform these operations. I was under the impression that it
automatically inherited the security profile of the user running the
application but it seems this is not the case.
Any help is greatly appreciated!
Regards,
David K
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob |
last post by:
I'm working on a Windows app that needs to write to the Registry HKLM. I
keep getting a "System.UnauthorizedAccessException: Cannot write to the
registry key." error when running the app. I'm logged in as an
Administrator and it's a Windows app. What permission does it need? Here's
the code.
private void ChangeReg() {
string regPath =
"SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders";
RegistryKey thisKey = Registry.LocalMachine;
|
by: csharp_helpwanted |
last post by:
steps..
first, I'm creating a connection by mapping a network drive to the pc
second, the map drive connection was successful I try to read a certian
registry key/value (that is a valid reg item)
third, I disconnect the network drive connection
it works great the first time
but if i run it again on the same pc anytime after that I get the following
|
by: g82martin |
last post by:
I am using the RegistryKey class to access the registry on remote
machines. I only require read access. I am able to successfully read
registry keys under HKLM\Software\Microsoft\Windows
NT\CurrentVersion\HotFix but I get a permissions error when I try to
access HKLM\Software\Network Associates\TVD\Shared Components\VirusScan
Engine\4.0.xx. The security permissions are identical on these two
keys. Here is my code:
RegistryKey...
|
by: Chakkaradeep |
last post by:
Hi all,
heres my code,
*******//////////////////////Starts
Here////////////////////////////////////*********
try
{
RegistryKey rKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\\AICM\\Position",true);
|
by: Thomas |
last post by:
Hi All,
When i am trying run the following code i am geting the error 'Object
reference not set to an instance of an object'
Try
Dim Reg As RegistryKey
Dim Value As String
Dim KeyValue As String = "Software\\MyCompany\\Connections"
Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)
| |
by: Steve Bottoms |
last post by:
Hi, all... Trying to determine how to check the state of OpenSubKey when
called. What is the return value if the requested subkey doesn't exist?? I
try a GetType on the result but only get a bizarre error, so I'm uncertain
what should be returned on both success or failure!
Thanks!
Jack
|
by: auldh |
last post by:
being a novice i searched the net to get help on my c# project.
i'm trying to iterate, enumerate, loop through a registry tree hive. for
example i have a sub folder under HKLM\SOFTWARE that has some 21 sub folders
and there are sub folders under some of he 21.
i have no problem going into the sub folder (lets call it) programX. when i
do an readkeys.opensubkey(regipath) and then keyvalue.getvalue(...) it will
not only read the "values"...
|
by: eSolTec, Inc. 501(c)(3) |
last post by:
Thank you in advance for any and all assistance. Here is my problem. I have a
program that will create a registry key, however it is not and here is the
code and also the error that follows:
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Imports System.Net
Imports Microsoft.VisualBasic.Conversion
Imports System.Management
|
by: Judith Schmidt |
last post by:
Hi
i need a way to set permission on a registry key where i have got not rights
to open it. But i am the owner (administrator).
The following code fails on OpenSubKey() with
System.Security.SecurityException: Requested registry access is not allowed
// ----start----
SetPermissions(){
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |