Connecting Tech Pros Worldwide Help | Site Map

Installer. Set registry key permissions

vavc1980's Avatar
Newbie
 
Join Date: Feb 2008
Location: College Station, TX
Posts: 21
#1: Sep 29 '09
I coded a windows service in Visual Studio 2005, I have the installer with it.
The registry keys for the service are created in System\controlset001\MyService.
The service is installed with LocalService account.

Problem is, after installing it, my service tries to add a key into that registry key location (intentionally added in the code), and it always fails because it does not have permissions, so I have to manually open the registry key and set permissions to LocalService, and start the service again.

Is there any way to set the permissions in the registry key at the installation process of the service?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#2: Sep 29 '09

re: Installer. Set registry key permissions


Quote:
The registry keys for the service are created in System\controlset001\MyService.
Which hive are you trying to do this in?
Personlly, I don't thing it should be in ...\System\ ... anything
The hives are organized with a subsection for Software. Generally by company name

HKEY_CURRENT_USER\SOFTWARE\MyCompanyName\MyProgram Name

Is the accepted standard.
vavc1980's Avatar
Newbie
 
Join Date: Feb 2008
Location: College Station, TX
Posts: 21
#3: Sep 29 '09

re: Installer. Set registry key permissions


It is in HKEY_LOCAL_MACHINE\SYSTEM\...

Thanks for the info. I did not know about the standard.
I did not specify that anywhere, that is where the installer created it.

Where can I specify that?
how about my original question about setting the permissions for the LocalService user when installing? do you have a suggestion?

Thanks.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#4: Sep 29 '09

re: Installer. Set registry key permissions


Quote:
did not specify that anywhere
Quote:
Problem is, after installing it, my service tries to add a key into that registry key location
I don't understand. Your program is trying to write a registry key, but you aren't specifying where? How can that be?

If you aren't saying where to write it, then how are (do you expect) to read it back?
vavc1980's Avatar
Newbie
 
Join Date: Feb 2008
Location: College Station, TX
Posts: 21
#5: Sep 29 '09

re: Installer. Set registry key permissions


Sorry I was not clear before.

When I install the service, it creates that path in the registry (with the description, displayname, errorcontrol, and other keys) in the location I told you before.

Of course in my code I'm using that path to create/read a key that I use for other purposes.
My original problem is that everytime I install the service that registry path does not have permissions for LocalService, thus my custom key cannot be created and I get an error. I need to open the registry manually and give the permissions then re-start the service and everything works fine.

Then you told me that the standard is to have the keys in HKEY_CURRENT_USER\SOFTWARE\MyCompanyName\MyProgram Name,
how can I specify that in the installer so when I install the service it creates all the keys in that path?, I obviously would update my code to write/read my custom key from that location.

I hope it is clear this time.

Thanks.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#6: Sep 29 '09

re: Installer. Set registry key permissions


I see what you are saying.
I believe the key you are trying to access is the key subset that tells windows the program is a service (and various other settings required to deal with it)
I think you will want your installer to install an additional key set in the standard location that tlhintoq pointed out. Then you should have the permissions for that keyset
vavc1980's Avatar
Newbie
 
Join Date: Feb 2008
Location: College Station, TX
Posts: 21
#7: Sep 30 '09

re: Installer. Set registry key permissions


Thanks Plater and tlhintoq for your suggestions.

I did what you guys suggested, in my installer project I went to the Registry section (right click on the project -> View -> Registry) and added my key in HKEY_CURRENT_USER\SOFTWARE\MyCompanyName\MyProgram Name.

Obviously I updated my code to read/write the value needed at that key. I seems like it works now without having to set the permission to Local_Service.
I'll be moving my project to QA soon, hopefully it'll work.

Thanks again!.
Reply

Tags
installation, registry key permissions, windows service


Similar .NET Framework bytes