0

I am trying to restart a windows service (part of the application) from my ASP.NET (.Net 4) application but it fails with the error:

Cannot open <ServiceName> service on computer '.'.
Inner Exception: Access is denied
StackTrace:  at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess)
   at System.ServiceProcess.ServiceController.Start(String[] args)
   at NetClient.AvailabilityConfiguration.StartAvailabilityService(ServiceController serviceName, TimeSpan timeout)

The code is working fine on my development machine (Windoes 7) and test server (Windows 2008 R2) but fails on the production server. The only (and BIG) difference is that UAC is turned ON the production serevr where as it is OFF on the dev and test servers.

I have tried adding an app.manifest file to the web application to get elevated privileges but it does not seem to work. I've configured the app.manifest "requestedExecutionLevel" attribute to "requireAdministrator" but does not seem to have an effect.

Any help will be greatly appreciated.

Thanks Aju

Aristos
  • 66,005
  • 16
  • 114
  • 150
Aju C
  • 3
  • 1
  • 2

1 Answers1

0

I think that is clear that the account that runs the pool of your web have not rights to manage the services (especial the Start, Stop, Pause commands).

See under what account your pool is running, and give him the permission to manage the services of your server. You can do that using the group policy, or open the security template.

Read the official detailed steps for How to grant users rights to manage services in Windows Server

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • I'm using in page (code) impersonation using a valid user having ull rights to start/stop the service. As mentioned, it does work on test/dev environments with the same set up. – Aju C May 21 '12 at 11:05
  • Is not the user, is the pool that must have the rights. Do you check what I have write that have permission ? – Aristos May 21 '12 at 11:08
  • Aristos, Thanks for your responses. I've used the subinacl tool to give required access permissions for the account that runs the application pool but still no joy! – Aju C May 22 '12 at 08:54
  • Aristos, I've marked your reply as the correct answer. Issue was with AppPool user not having the required rights to manage the service. As a note to others, subinacl.exe did not work for me for some reason, but the security template option worked a charm. Thanks a lot! – Aju C May 23 '12 at 08:30
  • anotehr thing I noted is that in this case you not need to do inline impersonation as I was doing becasue the apppool user itself has the rights to manage the service. – Aju C May 23 '12 at 08:31