?
Solved

Writing to the registry - from a service !

Posted on 2004-09-12
6
Medium Priority
?
322 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 1500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

770 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