I have to be able to start or stop an windows service (written in C#) from a C++ application say App.exe after the application has been started. I know I can give admin privileges to the app using a manifest before the application has been started. But can I do the same programmtically in C++ program in App.exe after the application has been started?
Asked
Active
Viewed 62 times
0
-
Possible duplicate of [Can a process elevate itself after startup?](http://stackoverflow.com/questions/2081945/can-a-process-elevate-itself-after-startup) – Harry Johnston Apr 18 '17 at 00:18
-
See also, e.g., http://stackoverflow.com/a/6418873/886887 – Harry Johnston Apr 18 '17 at 00:19
-
(Regarding your deleted question, assuming that an existing service has the default permissions, you must be running as administrator in order to change the permissions on it, in which case the call to OpenService will succeed.) – Harry Johnston Apr 18 '17 at 00:32
-
Instead, is it possible to programmatically set the permissions in the service exe if I am the developer of the windows service (like we do in the command "sc sdset
"? This way I do not have to elevate the other application from where I am trying to start or stop the windows service. -
The usual approach is to set the permissions appropriately at the time the service is installed. How you would best go about doing that depends on what sort of installer you are using. – Harry Johnston Apr 18 '17 at 04:30
-
What did you mean by what sort of installer? We are using InstallShield to build an installer exe from the service executable which has been built using Visual studio 2013. In installshield, can we set the permission of the service to be installed? (By permissions I mean DACL). – Arnoj Apr 18 '17 at 06:49
-
I've never used InstallShield, so I have no idea whether or not it has built-in support for setting the DACL of a system service. But if it doesn't, presumably there's some way to get it to run an arbitrary executable as part of setup, so you could write a very small program to change the DACL for you. (Or you could get it to run the `sc sdset` command you already mentioned.) – Harry Johnston Apr 18 '17 at 08:31
-
... it might be worth posting a new question, with the "installshield" tag, about the best way to do this. Although I note there's [308 existing questions](http://stackoverflow.com/search?q=%5Binstallshield%5D+service) about using InstallShield to install services, it would be best to search through that list first and see if there's an existing answer. – Harry Johnston Apr 18 '17 at 08:37
-
@HarryJohnston.. Thanks for all your comments. I will check about how to set it in the install scripts. – Arnoj Apr 18 '17 at 08:47
1 Answers
0
I put the following command in a .bat file SUBINACL /SERVICE /GRANT=S-1-5-32-545=TO > %1 and ran the bat file while installing the application from setup.exe. It resolved the issue. Thanks for your comments @Harry Johnston

Arnoj
- 79
- 8