简体   繁体   中英

Installing windows service on remote server

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM