The following code is throwing Exception. I don\'t get what mistake I am making in the code. Can somebody help me figure out please. I think it is of some security rights issue.
In my case, I determined that I needed to adjust the security on my service to allow it be be restarted by a separate "watchdog" service if my service fails.
First, open mmc.exe, then add the "Security Configuration and Analysis" and Security Templates" snap-ins.
Then create a new blank security template from the "Security Templates" item, give it a name, and hit OK to save it on your local disk drive somewhere convenient.
Then open "Security Configuration and Analysis" and choose "Open Database...", give it a name, and save it in the same directory as the previous step. When an "Import Template" window appears, open the *.inf file in the same directory.
Next, right-click "Security Configuration and Analysis" and choose "Analyze Computer..." The following will appear:
Double-click on "System Services", locate and double-click on your service, then click the checkbox "Define this policy in the database" and click on the "Edit Security" button.
This is where it becomes different than what is described in the link @JOG posted since I am using Windows 8.1--I enabled "start, stop and pause" for "INTERACTIVE" and "SERVICE"
FYI, I performed the above by following this guide as @JOG suggested: https://thommck.wordpress.com/2011/12/02/how-to-allow-non-admins-to-start-and-stop-system-services/