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

P

Parv

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.LocalMachine, "server");

RegistryKey sk1 =
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
in D:\Parv\Data\Visual
Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

What i am doing wrong ?

Thanx in advance.

With Best Regards
Parveen Beniwal
 
W

Willy Denoyette [MVP]

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.

|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.LocalMachine, "server");
|
| RegistryKey sk1 =
| baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
| in D:\Parv\Data\Visual
| Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
| at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| args)
| at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| checkAptModel)
| at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
| at
|
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| activationContext, String[] activationCustomData)
| at
|
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| activationContext)
| at
|
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
| at System.Threading.ThreadHelper.ThreadStart_Context(Object
| state)
| at System.Threading.ExecutionContext.Run(ExecutionContext
| executionContext, ContextCallback callback, Object state)
| at System.Threading.ThreadHelper.ThreadStart()
|
| What i am doing wrong ?
|
| Thanx in advance.
|
| With Best Regards
| Parveen Beniwal
|
 
P

Parv

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 said:
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.

|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.LocalMachine, "server");
|
| RegistryKey sk1 =
| baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
| in D:\Parv\Data\Visual
| Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
| at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| args)
| at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| checkAptModel)
| at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
| at
|
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| activationContext, String[] activationCustomData)
| at
|
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| activationContext)
| at
|
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
| at System.Threading.ThreadHelper.ThreadStart_Context(Object
| state)
| at System.Threading.ExecutionContext.Run(ExecutionContext
| executionContext, ContextCallback callback, Object state)
| at System.Threading.ThreadHelper.ThreadStart()
|
| What i am doing wrong ?
|
| Thanx in advance.
|
| With Best Regards
| Parveen Beniwal
|
 
W

Willy Denoyette [MVP]

Please be more specific, what's your own system and what account are you
running under?

Willy.

| 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.
| >
| > | > |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.LocalMachine, "server");
| > |
| > | RegistryKey sk1 =
| > |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
| > | in D:\Parv\Data\Visual
| > | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
| > | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| > | args)
| > | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| > | checkAptModel)
| > | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext, String[] activationCustomData)
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext)
| > | at
| > |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
| > | at System.Threading.ThreadHelper.ThreadStart_Context(Object
| > | state)
| > | at System.Threading.ExecutionContext.Run(ExecutionContext
| > | executionContext, ContextCallback callback, Object state)
| > | at System.Threading.ThreadHelper.ThreadStart()
| > |
| > | What i am doing wrong ?
| > |
| > | Thanx in advance.
| > |
| > | With Best Regards
| > | Parveen Beniwal
| > |
|
 
P

Parv

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
Please be more specific, what's your own system and what account are you
running under?

Willy.

| 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.
| >
| > | > |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.LocalMachine, "server");
| > |
| > | RegistryKey sk1 =
| > |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
| > | in D:\Parv\Data\Visual
| > | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
| > | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| > | args)
| > | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| > | checkAptModel)
| > | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext, String[] activationCustomData)
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext)
| > | at
| > |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
| > | at System.Threading.ThreadHelper.ThreadStart_Context(Object
| > | state)
| > | at System.Threading.ExecutionContext.Run(ExecutionContext
| > | executionContext, ContextCallback callback, Object state)
| > | at System.Threading.ThreadHelper.ThreadStart()
| > |
| > | What i am doing wrong ?
| > |
| > | Thanx in advance.
| > |
| > | With Best Regards
| > | Parveen Beniwal
| > |
|
 
W

Willy Denoyette [MVP]

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.


| 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.
| >
| > | > |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.LocalMachine, "server");
| > |
| > | RegistryKey sk1 =
| > |
baseKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\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.ThrowUnauthorizedAccessException(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(String[] srgs)
| > | in D:\Parv\Data\Visual
| > | Basic\MyEventSink\ExchangeConnect\SendMessage.cs:line 53
| > | at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
| > | args)
| > | at System.Runtime.Hosting.ManifestRunner.Run(Boolean
| > | checkAptModel)
| > | at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext, String[] activationCustomData)
| > | at
| > |
| >
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
| > | activationContext)
| > | at
| > |
| >
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
| > | at System.Threading.ThreadHelper.ThreadStart_Context(Object
| > | state)
| > | at System.Threading.ExecutionContext.Run(ExecutionContext
| > | executionContext, ContextCallback callback, Object state)
| > | at System.Threading.ThreadHelper.ThreadStart()
| > |
| > | What i am doing wrong ?
| > |
| > | Thanx in advance.
| > |
| > | With Best Regards
| > | Parveen Beniwal
| > |
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top