Can't open the service control manager despite running command prompt as administrator

6k views Asked by At

I created a service in C# which generated an executable "GodzillaService.exe". The service itself is just a basic template generated EXACTLY according to this link, other than the name: https://www.c-sharpcorner.com/article/create-windows-services-in-c-sharp/

The issue comes when I try to run InstallUtil. Per the article above, I execute

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 

on an elevated command prompt, run as administrator. I then type in

InstallUtil.exe C:\Path\To\My\EXE\Godzilla.exe

and I get hit with this error:

An exception occurred during the Install phase. System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges. The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: Access is denied.

Looking at the error message, experience tells me that I need to grant access to something or someone, but what? I'm already running the program as an administrator. I've tried these things so far:

  • Run command prompt as administrator.
  • Run Developer Command Prompt for VS 2017 as administrator.
  • Log out of my user account, log in to my admin account, and try running it.
  • Move the GodzillaService.exe file into Program Files directory in case applocker is messing with it.
  • Run VS 2017 as admin, rebuild the exe file, then try it.
  • Try using the full path of both the exe file and InstallUtil.
  • Made sure my admin account was in the local admin group.
  • Tried looking at Event Viewer for more information (did not find any logs related to this issue, maybe I'm looking in the wrong place?)
  • Tried changing the account in the service program from LocalSystem to User, LocalService, and to NetworkService

I'm fresh out of ideas... Does anyone have any suggestions for what I can do to further troubleshoot this problem? I appreciate any advice given!

1

There are 1 answers

0
nightmare637 On BEST ANSWER

It took me a while, but I was able to finally figure this out! The problem was that even though I said I was running it as an administrator, I was running it as a user with administrator privileges. Completely different.

In my environment (which is a domain environment), for some reason we have the "Run as Administrator" option blocked for running programs. Thus, to run things as an administrator, we actually have to run it as a different user, and then select our admin account. This works for 99% of things, but not for this case.

The solution was that I had to log completely out of my regular user account and log in with my administrative account. Then, I had to right click on command prompt and Run As Administrator. Upon doing this, I no longer received the error!