Skip to content

Instantly share code, notes, and snippets.

@jonnii
Created January 15, 2013 18:41
Show Gist options
  • Save jonnii/4540896 to your computer and use it in GitHub Desktop.
Save jonnii/4540896 to your computer and use it in GitHub Desktop.
function InstallService ($p,$s,$n,$e,$v) {
$stop = "$p\$s stop --environment=$e"
$uninstall = "$p\$s uninstall --environment=$e"
$install = "$p\$s install --environment=$e"
$start = "$p\$s start --environment=$e"
$serviceName = "$n$" + $e
$service = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'"
if ($service) {
stop-service $serviceName
$servicePath = "HKLM:\System\CurrentControlSet\services\$n`$$e\"
$description = "$n $e / $v"
$path = "`"$p\$s`" -instance:$e -displayname `"$n (Instance: $e)`" -servicename:$n"
Set-ItemProperty -path $servicePath -name Description -value "$description"
Set-ItemProperty -path $servicePath -name ImagePath -value "$path"
start-service $serviceName
}
else {
invoke-expression $install
invoke-expression $start
}
}
. .\InstallService.ps1
$serviceInstallerName = 'YourApp.exe'
$serviceName = 'YourApp'
InstallService $OctopusOriginalPackageDirectoryPath $serviceInstallerName $serviceName $OctopusEnvironmentName $OctopusPackageVersion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment