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.