1

Is it possible to install Windows service on a server remotely? I'm trying to do that with sc directive but gives me error:

sc \\remote_computer_IP create svc binPath="C:\Users\User\Documents\Visual Studio 2015\Projects\svc\svc\bin\Release\svc.exe" start= auto obj= "DOMAIN\usr" password= pass

[SC] OpenSCManager FAILED 5:

Access is denied.

Gilad Green
  • 36,708
  • 7
  • 61
  • 95

2 Answers2

2

Yes it is possible to do so with powershell, Microsoft recommends doing deployments and installations using powershell.

[SC] OpenSCManager FAILED 5 means you did not run the command in elevated command prompt (That is if you have Administrator access).

Here is a link that shows you how to deploy a windows service to a remote machine using powershell.

http://www.ben-morris.com/deploying-a-windows-service-remotely-with-powershell/

Softe Eng
  • 367
  • 1
  • 2
  • 8
1

You can establish a connection using net use, instead of using PS remoting:

net use "\\remote_computer_IP\c$" "[PASSWORD]" /USER:"[USERNAME]" /persistent:no
sc \\remote_computer_IP create svc binPath="C:\Users\User\Documents\Visual Studio 2015\Projects\svc\svc\bin\Release\svc.exe" start= auto obj= "DOMAIN\usr" password= pass
net use "\\$ComputerName\c$" /USER:"$Username" /delete

This assumes that your target machine has the service located in c:\users\user.

SC.exe will not copy your svc.exe to the target machine. In my use case, I am deploying a windows service to a farm of web boxes, and my goal was to include my service in my existing web deployment using MSBuild. My solution was to:

  • Deploy web components using MSBuild / Web Deploy (just like VS Publish)
  • Deploy the service in the same manner
    • I created a web project to target a website dedicated to the service, just to leverage the rest of my MSBuild project files.
    • Thus, I wound up with my service in c:\inetpub\MyService\bin

Then I call:

sc create \\remote_computer_IP "MyService" binpath="C:\inetpub\MyService\bin\MyService.exe"

Powershell is awesome, but PS remoting can be a pain when dealing with VPN tunneling and remote server farms.

Eric Patrick
  • 2,097
  • 2
  • 20
  • 31