I have programmed tools to handle this, not just for the base example script. However, I will talk about the main examples of scenarios.
The way the script package solves this problem is to call PsExec (one of the SysInternals tools). You can use PsExec to perform remote tasks. The credentials you need to provide must be the local administrator on the remote computer. For instance:
PsExec \\computername -u adminuser -p adminuserpassword somecommand somecommandarguments
If I wanted to copy a file between two directories, I could do the following:
PsExec \\computername -u adminuser -p adminuserpassword xcopy "C:\TestFile.txt" "C:\MyDir\TestFile.txt" /i /e /r /y
I like to load the SysInternals tools into the TOOLS directory and add this to my PATH environment variable, so I don't need to use the full path to PsExec.
You can combine this with packaging and installing Windows Service in MSI. In the MSI package, you can determine how to install the Windows service so that it starts with Windows, manually or in some other way. You can also set up a user account to run it. I always prefer to manually start the service. Use the MSIEXEC command-line tool to run the MSI package. You can combine these commands together to backup and deploy as follows:
PsExec \\computername -u adminuser -p adminuserpassword xcopy "\\buildserver\DeploymentPackages\MyWinService-v1\MyWinService.msi" "C:\Updates\MyWinService.msi" /i /e /r /y PsExec \\computername -u adminuser -p adminuserpassword MSIEXEC /i "C:\Updates\MyWinService.msi" INSTALLDIR="C:\Program Files (x86)\MyWinService" PsExec \\computername -u adminuser -p adminuserpassword sc start "MyWinService"
You do not need PsExec to run SC.exe on a remote computer, since it has the ability to specify a machine.
Hope this helps you here and there. I include links to the SysInternals and Windows Installer XML (WiX) tools for creating MSI packages from within Visual Studio.
PsExec from SysInternals Suite
Windows XML Installer (WiX)
source share