From: Ron Hinds on
I've been developing a Service in VB.NET. I set the serivce up to run under
the NETWORK_SERVICE account. I need to store several parameters for the
service to load on start from the registry. I tried to create a new subkey
in the service's ket that is created at install time, i.e.,
HKLM\SYSTEM\CurrentControlSet\Services\MyService. My idea was to create a
subkey called Parameters (like the Windows Time service does) and store my
data there. But I cannot even open that key - it always returns Nothing -
then I get an error missing parameter if I try to create it. So I figured I
would just create it under HKLM\SOFTWARE\MyCompany\MyService. I get the same
result. The only time it does not fail is when I use
HKCU\MyCompany\MyService. But that won't be available for my configuration
utility to make adjustments. It is appaerntly a permissions problem. Can
anyone point me to a good Registry exampe in VB.NET or tell me what is wrong
with this code?

rplBaseKey = Registry.LocalMachine.OpenSubKey("SYSTEM\Services\MyService",
RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl)

If rplBaseKey Is Nothing Then

'Should never happen - key is created automatically on install

rplBaseKey = Registry.LocalMachine.CreateSubKey("SYSTEM\Services\MyService",
RegistryKeyPermissionCheck.ReadWriteSubTree)

End If

rplParamKey = rplBaseKey.OpenSubKey("Parameters", True)

If rplParamKey Is Nothing Then

'Create the key if it doesn't exist

rplParamKey = rplBaseKey.CreateSubKey("Parameters")

End If




From: Ron Hinds on
"Ron Hinds" <nospam(a)dontspamme.com> wrote in message
news:u2H6yzy2KHA.3844(a)TK2MSFTNGP05.phx.gbl...
> I've been developing a Service in VB.NET. I set the serivce up to run
> under the NETWORK_SERVICE account. I need to store several parameters for
> the service to load on start from the registry. I tried to create a new
> subkey in the service's ket that is created at install time, i.e.,
> HKLM\SYSTEM\CurrentControlSet\Services\MyService. My idea was to create a
> subkey called Parameters (like the Windows Time service does) and store my
> data there. But I cannot even open that key - it always returns Nothing -
> then I get an error missing parameter if I try to create it. So I figured
> I would just create it under HKLM\SOFTWARE\MyCompany\MyService. I get the
> same result. The only time it does not fail is when I use
> HKCU\MyCompany\MyService. But that won't be available for my configuration
> utility to make adjustments. It is appaerntly a permissions problem. Can
> anyone point me to a good Registry exampe in VB.NET or tell me what is
> wrong with this code?
>
> rplBaseKey = Registry.LocalMachine.OpenSubKey("SYSTEM\Services\MyService",
> RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl)
>
> If rplBaseKey Is Nothing Then
>
> 'Should never happen - key is created automatically on install
>
> rplBaseKey =
> Registry.LocalMachine.CreateSubKey("SYSTEM\Services\MyService",
> RegistryKeyPermissionCheck.ReadWriteSubTree)
>
> End If
>
> rplParamKey = rplBaseKey.OpenSubKey("Parameters", True)
>
> If rplParamKey Is Nothing Then
>
> 'Create the key if it doesn't exist
>
> rplParamKey = rplBaseKey.CreateSubKey("Parameters")
>
> End If

Fixed - need to install service to run as "Local System" instead of "Network
Service" in Installer.