473,388 Members | 1,215 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,388 software developers and data experts.

Add and set a key in Remote Systems's registry in C#

I am working in a domain environment. I am on a client machine and
wants to edit registery of domain server. I am currently in a Domain
user account and member of Domain administrators on the domain
controller. I am able to open registry manully by connecting the remote
registry. While doing the same programatically i am getting the
following exception :

CODE :

RegistryKey baseKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");

RegistryKey sk1 =
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
string key = "incoming";
sk1.CreateSubKey(key);
sk1.SetValue(key, 1, RegistryValueKind.DWord);

EXCEPTION:

System.UnauthorizedAccessException was unhandled
Message="Cannot write to the registry key."
Source="mscorlib"
StackTrace:
at
System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
resource)
at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
registrySecurity)
at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
in D:\Parv\Data\Visual
Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

What i am doing wrong ?

Thanx in advance.

With Best Regards
Parveen Beniwal

Aug 11 '06 #1
5 7920
Are you sure the code runs as domain admin?
To make sure, turn on security auditing on the DC and watch the security
eventlog, this should contain a message specifying the account that failed
to access the registry object.

Willy.

"Parv" <Pa**********************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
|I am working in a domain environment. I am on a client machine and
| wants to edit registery of domain server. I am currently in a Domain
| user account and member of Domain administrators on the domain
| controller. I am able to open registry manully by connecting the remote
| registry. While doing the same programatically i am getting the
| following exception :
|
| CODE :
|
| RegistryKey baseKey =
| RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");
|
| RegistryKey sk1 =
| baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
| string key = "incoming";
| sk1.CreateSubKey(key);
| sk1.SetValue(key, 1, RegistryValueKind.DWord);
|
| EXCEPTION:
|
| System.UnauthorizedAccessException was unhandled
| Message="Cannot write to the registry key."
| Source="mscorlib"
| StackTrace:
| at
| System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
| resource)
| at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
| RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
| registrySecurity)
| at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
| at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
| in D:\Parv\Data\Visual
| Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
| at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| args)
| at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| checkAptModel)
| at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
| at
|
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| activationContext, String[] activationCustomData)
| at
|
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| activationContext)
| at
|
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
| at System.Threading.ThreadHelper.ThreadStart_Context( Object
| state)
| at System.Threading.ExecutionContext.Run(ExecutionCon text
| executionContext, ContextCallback callback, Object state)
| at System.Threading.ThreadHelper.ThreadStart()
|
| What i am doing wrong ?
|
| Thanx in advance.
|
| With Best Regards
| Parveen Beniwal
|
Aug 11 '06 #2
thanx, i have tried this but there is no security log for my Login
attempt on the DC. One more thing same is happenning when i am
attempting to edit my own system's registry. And on my system too there
is no log for login attempt.

With Best Regards
Parveen Beniwal
Willy Denoyette [MVP] wrote:
Are you sure the code runs as domain admin?
To make sure, turn on security auditing on the DC and watch the security
eventlog, this should contain a message specifying the account that failed
to access the registry object.

Willy.

"Parv" <Pa**********************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
|I am working in a domain environment. I am on a client machine and
| wants to edit registery of domain server. I am currently in a Domain
| user account and member of Domain administrators on the domain
| controller. I am able to open registry manully by connecting the remote
| registry. While doing the same programatically i am getting the
| following exception :
|
| CODE :
|
| RegistryKey baseKey =
| RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");
|
| RegistryKey sk1 =
| baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
| string key = "incoming";
| sk1.CreateSubKey(key);
| sk1.SetValue(key, 1, RegistryValueKind.DWord);
|
| EXCEPTION:
|
| System.UnauthorizedAccessException was unhandled
| Message="Cannot write to the registry key."
| Source="mscorlib"
| StackTrace:
| at
| System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
| resource)
| at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
| RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
| registrySecurity)
| at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
| at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
| in D:\Parv\Data\Visual
| Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
| at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| args)
| at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| checkAptModel)
| at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
| at
|
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| activationContext, String[] activationCustomData)
| at
|
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| activationContext)
| at
|
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
| at System.Threading.ThreadHelper.ThreadStart_Context( Object
| state)
| at System.Threading.ExecutionContext.Run(ExecutionCon text
| executionContext, ContextCallback callback, Object state)
| at System.Threading.ThreadHelper.ThreadStart()
|
| What i am doing wrong ?
|
| Thanx in advance.
|
| With Best Regards
| Parveen Beniwal
|
Aug 12 '06 #3
Please be more specific, what's your own system and what account are you
running under?

Willy.

"Parv" <Pa**********************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
| thanx, i have tried this but there is no security log for my Login
| attempt on the DC. One more thing same is happenning when i am
| attempting to edit my own system's registry. And on my system too there
| is no log for login attempt.
|
| With Best Regards
| Parveen Beniwal
| Willy Denoyette [MVP] wrote:
| Are you sure the code runs as domain admin?
| To make sure, turn on security auditing on the DC and watch the security
| eventlog, this should contain a message specifying the account that
failed
| to access the registry object.
| >
| Willy.
| >
| "Parv" <Pa**********************@gmail.comwrote in message
| news:11*********************@m73g2000cwd.googlegro ups.com...
| |I am working in a domain environment. I am on a client machine and
| | wants to edit registery of domain server. I am currently in a Domain
| | user account and member of Domain administrators on the domain
| | controller. I am able to open registry manully by connecting the
remote
| | registry. While doing the same programatically i am getting the
| | following exception :
| |
| | CODE :
| |
| | RegistryKey baseKey =
| | RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");
| |
| | RegistryKey sk1 =
| |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
| | string key = "incoming";
| | sk1.CreateSubKey(key);
| | sk1.SetValue(key, 1, RegistryValueKind.DWord);
| |
| | EXCEPTION:
| |
| | System.UnauthorizedAccessException was unhandled
| | Message="Cannot write to the registry key."
| | Source="mscorlib"
| | StackTrace:
| | at
| | System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
| | resource)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
| | RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
| | registrySecurity)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
| | at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
| | in D:\Parv\Data\Visual
| | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
| | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| | args)
| | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| | checkAptModel)
| | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext, String[] activationCustomData)
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext)
| | at
| |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
| | at System.Threading.ThreadHelper.ThreadStart_Context( Object
| | state)
| | at System.Threading.ExecutionContext.Run(ExecutionCon text
| | executionContext, ContextCallback callback, Object state)
| | at System.Threading.ThreadHelper.ThreadStart()
| |
| | What i am doing wrong ?
| |
| | Thanx in advance.
| |
| | With Best Regards
| | Parveen Beniwal
| |
|
Aug 13 '06 #4
ok, let me elaborate my case again.Actually i m working on a windows
2000 professional client system and working in a 2000 Advanced server
Domain environment. And i am using my own user account as
parveen.beniwal which is member of Domain admins and Administrator on
the Domain Controller. Now i want to update registry of my domain
controller from my client computer. I am able to do this manually but
programatically. Please help..
With Best Regards
Parveen Beniwal

Willy Denoyette [MVP] wrote:
Please be more specific, what's your own system and what account are you
running under?

Willy.

"Parv" <Pa**********************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
| thanx, i have tried this but there is no security log for my Login
| attempt on the DC. One more thing same is happenning when i am
| attempting to edit my own system's registry. And on my system too there
| is no log for login attempt.
|
| With Best Regards
| Parveen Beniwal
| Willy Denoyette [MVP] wrote:
| Are you sure the code runs as domain admin?
| To make sure, turn on security auditing on the DC and watch the security
| eventlog, this should contain a message specifying the account that
failed
| to access the registry object.
| >
| Willy.
| >
| "Parv" <Pa**********************@gmail.comwrote in message
| news:11*********************@m73g2000cwd.googlegro ups.com...
| |I am working in a domain environment. I am on a client machine and
| | wants to edit registery of domain server. I am currently in a Domain
| | user account and member of Domain administrators on the domain
| | controller. I am able to open registry manully by connecting the
remote
| | registry. While doing the same programatically i am getting the
| | following exception :
| |
| | CODE :
| |
| | RegistryKey baseKey =
| | RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");
| |
| | RegistryKey sk1 =
| |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
| | string key = "incoming";
| | sk1.CreateSubKey(key);
| | sk1.SetValue(key, 1, RegistryValueKind.DWord);
| |
| | EXCEPTION:
| |
| | System.UnauthorizedAccessException was unhandled
| | Message="Cannot write to the registry key."
| | Source="mscorlib"
| | StackTrace:
| | at
| | System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
| | resource)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
| | RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
| | registrySecurity)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
| | at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
| | in D:\Parv\Data\Visual
| | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
| | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| | args)
| | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| | checkAptModel)
| | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext, String[] activationCustomData)
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext)
| | at
| |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
| | at System.Threading.ThreadHelper.ThreadStart_Context( Object
| | state)
| | at System.Threading.ExecutionContext.Run(ExecutionCon text
| | executionContext, ContextCallback callback, Object state)
| | at System.Threading.ThreadHelper.ThreadStart()
| |
| | What i am doing wrong ?
| |
| | Thanx in advance.
| |
| | With Best Regards
| | Parveen Beniwal
| |
|
Aug 13 '06 #5
Sorry if I wasn't clear, but you have to enable "registry object access"
auditing, that is from regedit select the key you want to audit and add the
user or group you want to monitor. Then, using "Local Security Policy"
editor, you must turn-on; Local Policies - Audit Policy - Audit Object
Access for Failure. When done, each unsuccessful access will be logged in
security log and will contain the account used to modify a key or subkey.
Willy.
"Parv" <Pa**********************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
| thanx, i have tried this but there is no security log for my Login
| attempt on the DC. One more thing same is happenning when i am
| attempting to edit my own system's registry. And on my system too there
| is no log for login attempt.
|
| With Best Regards
| Parveen Beniwal
| Willy Denoyette [MVP] wrote:
| Are you sure the code runs as domain admin?
| To make sure, turn on security auditing on the DC and watch the security
| eventlog, this should contain a message specifying the account that
failed
| to access the registry object.
| >
| Willy.
| >
| "Parv" <Pa**********************@gmail.comwrote in message
| news:11*********************@m73g2000cwd.googlegro ups.com...
| |I am working in a domain environment. I am on a client machine and
| | wants to edit registery of domain server. I am currently in a Domain
| | user account and member of Domain administrators on the domain
| | controller. I am able to open registry manully by connecting the
remote
| | registry. While doing the same programatically i am getting the
| | following exception :
| |
| | CODE :
| |
| | RegistryKey baseKey =
| | RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMa chine, "server");
| |
| | RegistryKey sk1 =
| |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Serv ices\EXIFS\Parameters");
| | string key = "incoming";
| | sk1.CreateSubKey(key);
| | sk1.SetValue(key, 1, RegistryValueKind.DWord);
| |
| | EXCEPTION:
| |
| | System.UnauthorizedAccessException was unhandled
| | Message="Cannot write to the registry key."
| | Source="mscorlib"
| | StackTrace:
| | at
| | System.ThrowHelper.ThrowUnauthorizedAccessExceptio n(ExceptionResource
| | resource)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey,
| | RegistryKeyPermissionCheck permissionCheck, RegistrySecurity
| | registrySecurity)
| | at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)
| | at MyEventSink.ExchangeConnect.SendMessage.Main(Strin g[] srgs)
| | in D:\Parv\Data\Visual
| | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:l ine 53
| | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| | args)
| | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| | checkAptModel)
| | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext, String[] activationCustomData)
| | at
| |
| >
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
| | activationContext)
| | at
| |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
| | at System.Threading.ThreadHelper.ThreadStart_Context( Object
| | state)
| | at System.Threading.ExecutionContext.Run(ExecutionCon text
| | executionContext, ContextCallback callback, Object state)
| | at System.Threading.ThreadHelper.ThreadStart()
| |
| | What i am doing wrong ?
| |
| | Thanx in advance.
| |
| | With Best Regards
| | Parveen Beniwal
| |
|
Aug 14 '06 #6

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

Similar topics

3
by: Slimo | last post by:
Hello, I'm searching some example of code (VB) for reading remote registry subkeys and keys. Thanks
0
by: Anton Sokolovsky | last post by:
Hello All, Please help. I am completely stuck. Any suggestions are very welcomed. I have ASP.NET application that impersonates certain user <impersonate="true" userName="registry:..."...
3
by: Steve Montgomery | last post by:
Does anyone have a sample block of code they can share for checking a DWORD value on a remote network machine's registry? For example, to validate a patch deployment. MSDN has a great sample for...
1
by: JJG | last post by:
Hello. I'm not sure if this is the right forum, so please let me know what is the correct one if it isn't. (I posted this one also to the win32.programmer.wmi forum). I've been puzzled by this...
3
by: Geoff McElhanon | last post by:
I have been struggling with a security issue that occurs under .NET 2.0, but does not occur under .NET 1.1. Essentially I am trying to open up a performance counter on a remote server and monitor...
5
by: Sin Jeong-hun | last post by:
I need to read some registry keys of a remote computer. The key will be any key users provide. (For example : HKEY_CURRENT_USER\SOFTWARE \MyGame) I found that there was a handy method called...
12
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i current have a way to read both local and remote machines registry keys and create a textual view (.txt output). i now looking for ways to do export of local and remote mahcine registry keys...
4
by: Kerem Gümrükcü | last post by:
Hi, is it possible to get the Information that comes from OperatingSystem Class from a Remote Comupter. Is there a remote information supporting OperatingSystem Class or can i get this...
6
tlhintoq
by: tlhintoq | last post by:
I pride myself on being able to Google just about anything but... I have fought, tried, searched and fought some more on this one. I am using VMware, and am able to debug from Visual Studio to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.