Solved

Writing to the registry - from a service !

Posted on 2004-09-12
6
314 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

810 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