Solved

Writing to the registry - from a service !

Posted on 2004-09-12
6
311 Views
Last Modified: 2010-04-01
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?

0
Comment
Question by:manoj_johar
6 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12041618
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
0
 

Author Comment

by:manoj_johar
ID: 12041640
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 !
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 12041658
It's has less to do with priviliges but that the system has to know *which* user rights the service is supposed to get.

I would recommend the GUI approach as you don't need to hold a valid user password in your program and have to make the logon only once.

Note, if you have a domain user, you have to define like  domain\username.

Regards, Alex


 
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12041694
>> 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

0
 
LVL 86

Expert Comment

by:jkr
ID: 12043559
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)
0
 
LVL 3

Expert Comment

by:double_axe
ID: 12052906
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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now