Solved

Writing to the registry - from a service !

Posted on 2004-09-12
6
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 144
Error C2678: binary '!=': no operator found... 4 71
How do I get Window Title of all opened process? 4 60
Need some help with design 17 46
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

737 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