Windows Service

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

I am trying to access the registry from a Windows service... My code is
trying to set value to one of the subkey's for HKEY_CURRENT_USER, but it
keeps putting the value under HKEY_USERS everytime...I have tried running
the service as Administrator, a user with Administrative privileges.. , the
current logged on user. I cannot get the service to put the entry in
HKEY_CURRENT_USER.. How can I achieve this?? Is this not possible to do with
..NET and the Microsoft.Win32 classes?

My Requirement is this.. I need to manipulate a registry key
programmatically under HKEY_CURRENT_USER, no matter which type of user is
logged in XP.

VJ
 
VJ said:
I am trying to access the registry from a Windows service... My code is
trying to set value to one of the subkey's for HKEY_CURRENT_USER, but it
keeps putting the value under HKEY_USERS everytime...I have tried running
the service as Administrator, a user with Administrative privileges.. , the
current logged on user. I cannot get the service to put the entry in
HKEY_CURRENT_USER.. How can I achieve this?? Is this not possible to do
with .NET and the Microsoft.Win32 classes?

My Requirement is this.. I need to manipulate a registry key
programmatically under HKEY_CURRENT_USER, no matter which type of user is
logged in XP.

VJ

You can't, the service runs in a non interactive logon session, that means
that the profile of the service user is not loaded. This is by design,
services are meant to run in the background and should/do not require a user
profile to be loaded (no interactive logon). Or simply put, services should
not read/write to HKCU. If you really need this, you'll have to load the
profile yourself by PInvoking Win32's LoadUserProfile. Check the platform
sdk docs. in MSDN for more info on the LoadUserProfile API.

Willy.
 
I have not used PInovke... or C++ API's from C#.. can somebody give me a
outline of How I would do this in C#?

VJ
 
If I may ask, what was the original problem you were trying to solve by
writing to HKEY_CURRENT_USER? What information are you trying to
persist and why?

If there is no current user by design, perhaps there's a better way to
do what you're trying to do, without resorting to loading user profiles
via PInvoke.
 

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

Back
Top