尝试配置Windows服务的失败操作失败并显示访问被拒绝错误

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?