Skip to content

Commit

Permalink
added ability to set Displayname, Description and StartupType
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkChaos committed Jun 17, 2020
1 parent ae94657 commit 424e2c4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,31 @@ if ($InstallService) {
}
}

# Set default values of optional parameters.
if (-not $ServiceDisplayName) {
$ServiceDisplayName = $ServiceName
}

# fix ServiceName (can not contain Spaces)
if ($ServiceName.Contains(' ')) {
$ServiceName = $ServiceName.Replace(' ', '')
}

$scriptBlock = {
$serviceName = $args[0]
$Timeout = $args[1]
$StopProcess = $args[2]
$CleanInstall = $args[3]
$ArtifactPath = $args[4]
$installationPath = $args[5]
$runAsCredential = $args[6]
$installTopShelfService = $args[7]
$instanceName = $args[8]
$installArguments = $args[9]
$startService = $args[10]
$serviceName = $args[0]
$serviceDisplayName = $args[1]
$serviceDescription = $args[2]
$serviceStartupType = $args[3]
$Timeout = $args[4]
$StopProcess = $args[5]
$CleanInstall = $args[6]
$ArtifactPath = $args[7]
$installationPath = $args[8]
$runAsCredential = $args[9]
$installTopShelfService = $args[10]
$instanceName = $args[11]
$installArguments = $args[12]
$startService = $args[13]

if ($instanceName.Length -ne 0) {
Write-Output "[$env:ComputerName]: Instance Name: [$instanceName]"
Expand Down Expand Up @@ -139,14 +152,29 @@ $scriptBlock = {
$freshTopShelfInstall = $true
}
else {
if ($serviceStartupType -eq "Delayed") {
$startupType = "Automatic"
$delayed = $true
}
else {
$startupType = $serviceStartupType
$delayed = $false
}

$newServiceSplat = @{
Name = $ServiceName
BinaryPathName = $installationPath
DisplayName = $serviceDisplayName
Description = $serviceDescription
StartupType = $startupType
}
if ($runAsCredential) {
$newServiceSplat.Credential = $runAsCredential
}
$newService = New-Service @newServiceSplat

if ($delayed) {
Start-Process -FilePath sc.exe -ArgumentList "config ""$ServiceName"" start=delayed-auto"
}
}
}

Expand Down Expand Up @@ -256,5 +284,5 @@ if ($useSSL) {
$invokeCommandSplat.UseSSL = $true
}

Invoke-Command @invokeCommandSplat -ArgumentList $ServiceName, $TimeOut, $StopProcess, $CleanInstall, $ArtifactPath, $installationPath, $runAsCredential, $installTopShelfService, $instanceName, $installArguments, $startService
Invoke-Command @invokeCommandSplat -ArgumentList $ServiceName, $serviceDisplayName, $serviceDescription, $serviceStartupType, $TimeOut, $StopProcess, $CleanInstall, $ArtifactPath, $installationPath, $runAsCredential, $installTopShelfService, $instanceName, $installArguments, $startService
Trace-VstsLeavingInvocation $MyInvocation
34 changes: 32 additions & 2 deletions WindowsServiceManager/WindowsServiceManagerV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"preview": false,
"version": {
"Major": 4,
"Minor": 3,
"Patch": 5
"Minor": 4,
"Patch": 0
},
"instanceNameFormat": "Deploy Windows Service",
"groups": [
Expand Down Expand Up @@ -87,6 +87,36 @@
"required": true,
"helpMarkDown": "The exact name of the windows service installed on the deployment group target."
},
{
"name": "ServiceDisplayName",
"type": "string",
"label": "Service Displayname",
"defaultValue": "",
"required": false,
"helpMarkDown": "The Displayname of the windows service."
},
{
"name": "ServiceDescription",
"type": "string",
"label": "Service Description",
"defaultValue": "",
"required": false,
"helpMarkDown": "The Displayname of the windows service."
},
{
"name": "ServiceStartupType",
"type": "radio",
"label": "Service Startup Type",
"defaultValue": "Automatic",
"required": true,
"helpMarkDown": "The path to the windows service artifact.",
"options": {
"Automatic": "Automatic",
"Delayed": "Automatic (Delayed Start)",
"Manual": "Manual",
"Disabled": "Disabled"
}
},
{
"name": "ArtifactPath",
"type": "filePath",
Expand Down

0 comments on commit 424e2c4

Please sign in to comment.