Write to HKLM from windows Service

D

Dan Holmes

I am trying to write to the HKLM hive from a service. I can read from it just fine. I have what i believe to be the
correct code but i am getting access violations.

RouteMatch.CM.ProtocolTestHarness.SetRegistryKey:
System.UnauthorizedAccessException: Cannot write to the registry key.
at System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.EnsureWriteable()
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at RouteMatch.CM.RMCMService.SetRegistryValue(String message) in C:\Sandbox\DM71740 - Client
Managment\src\RMCMS\RMCM.cs:line 192
at RouteMatch.CM.RMCMService.ProcessMessage(Object clientState) in C:\Sandbox\DM71740 - Client
Managment\src\RMCMS\RMCM.cs:line 118
Expected: 0
But was: -99

My service is logged in a the local administrator and Permissions for that key for the local Admin are Full Control. I
don't know what to check or how to debug this further. I can step into the code and follow the throw at .SetValue but i
don't know what else to try. What else can i try?

thanks

danny
 
D

Dan Holmes

Dan said:
I am trying to write to the HKLM hive from a service. I can read from
it just fine. I have what i believe to be the correct code but i am
getting access violations.

RouteMatch.CM.ProtocolTestHarness.SetRegistryKey:
System.UnauthorizedAccessException: Cannot write to the registry key.
at
System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource
resource)
at Microsoft.Win32.RegistryKey.EnsureWriteable()
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value,
RegistryValueKind valueKind)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at RouteMatch.CM.RMCMService.SetRegistryValue(String message) in
C:\Sandbox\DM71740 - Client Managment\src\RMCMS\RMCM.cs:line 192
at RouteMatch.CM.RMCMService.ProcessMessage(Object clientState) in
C:\Sandbox\DM71740 - Client Managment\src\RMCMS\RMCM.cs:line 118
Expected: 0
But was: -99

My service is logged in a the local administrator and Permissions for
that key for the local Admin are Full Control. I don't know what to
check or how to debug this further. I can step into the code and follow
the throw at .SetValue but i don't know what else to try. What else can
i try?

thanks

danny
Well i figured it out and i feel like a dummy.

..OpenSubKey(@"Software\RouteMatch\" + k.Path, RegistryKeyPermissionCheck.ReadWriteSubTree);
 

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