Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Who knows a simple solution how to install or uninstall a Windows service remotely on a Win2k8R2 server?

This server is a hosted at the internet, so it's not in a domain or such. Thus I want to avoid the use of windows file sharing or administration services.

I would prefer a possibility where I can trigger the execution of a server-side script which installs already uploaded service-binaries.

You're welcome to name any tools or .NET code solutions if you know how to accomplish that.

Edit: Sorry, I have to clarify a bit, it's not as easy as using powershell or scripting with InstallUtil in my case. I'll try it with bullet points:

  • I want to install a service unattendedly by invoking the service installation on a server, running on the internet, from a client.
  • I don't have a GUI from the server while invoking the service install. For example, I trigger a setup.exe, which installs the services itself via SSH (self-installing service to make use of custom service names). Not having a GUI seems to be a problem(?).

I even tried desperately to invoke the service setup program via a php web service (shell_exec), but the result is always the same: Setup is executed, but no services are installed.

To the client it should be as easy as possible to invoke the service installation on the server, without seeing anything of it. It's for a periodic and automated deployment of some service-based applications we create.

share|improve this question
    
This sounds like a programming question, perhaps it should be on stackoverflow instead of superuser? –  Harry Johnston Sep 20 '11 at 21:17
    
Is the installer (setup.exe) your own code? –  Harry Johnston Sep 20 '11 at 21:19
    
Its our own installer, yes, and here at superuser I'm actually looking for a non-programming answer (although I could handle that as well ;) ). I'm quite certain it's possible to remote-install a windows service on an internet host unattendedly. Or prove me wrong ;) –  derFunk Sep 21 '11 at 8:06
    
From what you've said, though, the problem seems to be that your setup.exe doesn't work properly when invoked remotely. Fixing this problem would be a programming question. If you're looking for an existing solution, I don't understand what you want that solution to do other than run setup.exe, which you've already tried. –  Harry Johnston Sep 22 '11 at 21:17
    
The installer is not doing anything else than what can be done via command line. So forget the setup.exe for now. My most urgent question is: Is there any way to remotely install a windows service on an Win2k8 Server machine running on the internet? –  derFunk Oct 12 '11 at 11:45

2 Answers 2

Powershell seems like a likely option. Take a look at the cmdlet reference and the Add-WindowsFeature cmdlet

share|improve this answer
    
Powershell is the way of the future. Even Microsoft has started creating all their diagnostic tools on top of Powershell. –  surfasb Sep 20 '11 at 16:33
    
Its a server machine running on the internet, I wouldn't open windows file sharing services to the public here. Is powershell still an option now? Anyone really tried already to remotely install a service on an internet server? (every tunnel thinkable is possible). –  derFunk Oct 12 '11 at 11:47
    
Powershell v2's remoting service runs over an ssh-like connection. –  uSlackr Oct 12 '11 at 12:56

I did this recently using PowerShell and WMI. Full details here but in a nutshell something like the below works, as well as PowerShell remoting or SC.exe

function Install-Service(
[string]$serviceName = $(throw "serviceName is required"),
[string]$targetServer = $(throw "targetServer is required"),
[string]$displayName = $(throw "displayName is required"),
[string]$physicalPath = $(throw "physicalPath is required"),
[string]$userName = $(throw "userName is required"),
[string]$password = "",
[string]$startMode = "Automatic",
[string]$description = "",
[bool]$interactWithDesktop = $false
)
{        
# todo: cleanup this section
$serviceType = 16          # OwnProcess
$serviceErrorControl = 1   # UserNotified
$loadOrderGroup = $null
$loadOrderGroupDepend = $null
$dependencies = $null

# description?
$params = `
    $serviceName, `
    $displayName, `
    $physicalPath, `
    $serviceType, `
    $serviceErrorControl, `
    $startMode, `
    $interactWithDesktop, `
    $userName, `
    $password, `
    $loadOrderGroup, `
    $loadOrderGroupDepend, `
    $dependencies `

$scope = new-object System.Management.ManagementScope("\\$targetServer\root\cimv2", `
    (new-object System.Management.ConnectionOptions))
"Connecting to $targetServer"
$scope.Connect()
$mgt = new-object System.Management.ManagementClass($scope, `
    (new-object System.Management.ManagementPath("Win32_Service")), `
    (new-object System.Management.ObjectGetOptions))

$op = "service $serviceName ($physicalPath) on $targetServer"   
"Installing $op"
$result = $mgt.InvokeMethod("Create", $params)   
Test-ServiceResult -operation "Install $op" -result $result
"Installed $op"

"Setting $serviceName description to '$description'"
Set-Service -ComputerName $targetServer -Name $serviceName -Description $description
"Service install complete"
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.