Link to home
Start Free TrialLog in
Avatar of manoj_johar
manoj_johar

asked on

Writing to the registry - from a service !

Hi,
   I'm building a windows service. I need to write some entries to the registry. I used the SDK functions RegOpenKey, RegSetValue etc...but the registry is not getting updated :-(   Thing is that the same piece of code works fine when I run it as an EXE or as a DLL! There is no exceptions thrown also !  Ne idea about this one?

Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

A service needs a valid account when accessing resources like network or registry.

You either should stop the service using GUI applet of Service Control Manager (SCM) and restart it by giving a valid user account or give account information other than LocalSystem account when installing the service.

Regards, Alex
Avatar of manoj_johar
manoj_johar

ASKER

Local System account has the highest privileges right? There shouldnt be a problem when I use that I guess?
Funny thing is that I'm able to read from the registry but not able to write to it !
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> Funny thing is that I'm able to read from the registry but not able to write to it !

The registry has two parts - a system part and a user part. Services get started to a time where no user is logged in. Then, only the system part of the registry would have been available.

The concept to give write access only if a valid user could be provided  is necessary for the security concept of the registry. You'll have similar problems with file access and network access as there is no way to define access rights of LocalSystem account.

Regards, Alex

Avatar of jkr
Check the return values from the API functions. Chances are that you are writing to a key that requires administrative provileges or is secured in a different way. Also check that using RegMon (http://www.sysinternals.com/ntw2k/source/regmon.shtml). And, post some code :o)
I think that it is because "Local Service" account under which services particulary run has access to other registry account than logged on user. Check the article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/localsystem_account.asp