all groups > dotnet myservices > october 2004 >
You're in the

dotnet myservices

group:

How to access remote registry from a windows service?



How to access remote registry from a windows service? Sheri Sourbeck
10/21/2004 10:04:13 AM
dotnet myservices: I have a Windows service written in VB.net that needs read-only access to a
remote registry. When the service attempts to access this registry I get
"Access to the registry key is denied". The service is running on a Win2K
system and the remote registry is on another Win2K system. The code works
just fine from a Windows application, just not from a service.

I have the following code in my service class:
Imports System.Security.Permissions

<Assembly: RegistryPermissionAttribute(
SecurityAction.RequestMinimum, Read:="HKEY_LOCAL_MACHINE\SOFTWARE")>

<Assembly: SecurityPermissionAttribute(
SecurityAction.RequestMinimum, UnmanagedCode:=True)>

My code that accesses the remote registry is in another class and looks like
this:

remotekey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
"\\" & m_sServerIPAddress)

rkey = remotekey.OpenSubKey("SOFTWARE\ComputingDevices\OMT", False)

sCurrentVersion = rkey.GetValue("CurrentVersion")

Thanks in advance for your help.

Re: How to access remote registry from a windows service? Lee Gillie
10/25/2004 3:04:53 PM
Use a domain logon that can access remote registries for your service
rather than local system, which is the default. Services running under
local system have no network access.

[quoted text, click to view]
Re: How to access remote registry from a windows service? Sheri Sourbeck
10/27/2004 8:10:59 AM
That did the trick! Thanks!

[quoted text, click to view]
AddThis Social Bookmark Button