469,643 Members | 1,908 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

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 7562
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Slimo | last post: by
reply views Thread by Anton Sokolovsky | last post: by
3 posts views Thread by Steve Montgomery | last post: by
5 posts views Thread by Sin Jeong-hun | last post: by
12 posts views Thread by =?Utf-8?B?YXVsZGg=?= | last post: by
4 posts views Thread by Kerem Gümrükcü | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.