1

I want to configure the failure actions for a service I have written in Go. I am following the answer posted at following page: How do I configure failure actions of a Windows service written in Go?

The function call ChangeServiceConfig2 returns "Access is denied." error in my case (when the 2nd parameter is SERVICE_CONFIG_FAILURE_ACTIONS).

I am running as Administrator so I don't understand why this function gives "Access denied" error.

I can use the function ChangeServiceConfig2 to perform other actions (e.g. to set the start type for my service as Automatic Delayed, using 2nd parameter as SERVICE_CONFIG_DELAYED_AUTO_START_INFO).

Has anyone had similar issue when using ChangeServiceConfig2 to set failure actions for a Windows service? What is the solution in that case?

kostix
  • 51,517
  • 14
  • 93
  • 176
bvk
  • 39
  • 2
  • 1
    [this](https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/2bea77d5-52e3-4683-acac-1c28b2d9109f/changeserviceconfig2-failing-with-erroraccessdenied?forum=windowsgeneraldevelopmentissues)? (And [this](https://www.google.com/search?q=ChangeServiceConfig2+failure+action+access+denied) in general). – kostix Oct 31 '17 at 14:12
  • I had already looked at the links you provided, but was unable to solve the problem. I am using CreateService and OpenProcess both with SERVICE_ALL_ACCESS access rights, and they don't give any error. I get "access denied" when I use ChangeServiceConfig2 later for the same service. – bvk Oct 31 '17 at 14:24

2 Answers2

0

as mentioned here: https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.kernel/_McV5qokCR8

...you need to enable SE_SHUTDOWN_NAME privilege.

Credit goes to Alex Fedotov

grim.ub
  • 192
  • 2
  • 11
0

Ran into this too recently. I was using SC_ACTION_RESTART as a type of action and SERVICE_CHANGE_CONFIG was not enough (ERROR_ACCESS_DENIED). Turned out you need to open the service handle with SERVICE_START access right.

fmike7
  • 56
  • 5