Search code examples
windowswindows-serviceshostssc.exe

Service Control Manager (sc.exe) fails when using a localhost alias in hosts file, but succeeds when using the loopback address directly


I am running the command:

sc \\My-Server create TestService binPath= "C:\Test\Test.exe"

However, it fails with

[SC] OpenSCManager FAILED 5:

Access is denied.

My hosts file contains:

127.0.0.1 My-Server

However, if I do the command below, it works just fine!

sc \\127.0.0.1 create TestService binPath= "C:\Test\Test.exe"
[SC] CreateService SUCCESS

I am running cmd as admin. Any ideas?


Solution

  • Resolved. I found this thread: https://serverfault.com/questions/184098/why-cant-i-access-an-administrative-share-on-my-local-machine

    Step 2: "Allowing server machine to use filesharing with itself via the DNS Alias (BackConnectionHostNames)" is what fixed it for me. I added a multi-string value called BackConnectionHostNames in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0 and gave it a value of My-Server. Ran the sc command again, and it worked.