Windows Service - Set Startup Type

Octopus.Script exported 2014-09-16 by caioproiete belongs to ‘Windows’ category.

Sets the Startup Type of a Windows Service

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Service Name

ServiceName

Name of the Windows Service (this is not always the display name).

Startup Type

StartupType = auto

Startup type of the Windows Service.

Script body

Steps based on this template will execute the following PowerShell script.

$serviceName = $OctopusParameters['ServiceName']
$startupType = $OctopusParameters['StartupType']

if (!$serviceName)
{
    Write-Error "No service name was specified. Please specify the name of the service to set the 'Startup Type'."
    exit -2
}

Write-Output "Setting Startup Type for $serviceName..."

sc.exe config $serviceName start= $startupType

Write-Output "Startup Type for $serviceName set to $startupType."

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "361926f3-8c53-4d19-bb3b-337a531e4448",
  "Name": "Windows Service - Set Startup Type",
  "Description": "Sets the Startup Type of a Windows Service",
  "Version": 1,
  "ExportedAt": "2014-09-16T00:19:29.865+00:00",
  "ActionType": "Octopus.Script",
  "Author": "caioproiete",
  "Parameters": [
    {
      "Name": "ServiceName",
      "Label": "Service Name",
      "HelpText": "Name of the Windows Service (this is not always the display name).",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StartupType",
      "Label": "Startup Type",
      "HelpText": "Startup type of the Windows Service.",
      "DefaultValue": "auto",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "delayed-auto|Automatic (Delayed Start)\nauto|Automatic\ndemand|Manual\ndisabled|Disabled"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "$serviceName = $OctopusParameters['ServiceName']\n$startupType = $OctopusParameters['StartupType']\n\nif (!$serviceName)\n{\n    Write-Error \"No service name was specified. Please specify the name of the service to set the 'Startup Type'.\"\n    exit -2\n}\n\nWrite-Output \"Setting Startup Type for $serviceName...\"\n\nsc.exe config $serviceName start= $startupType\n\nWrite-Output \"Startup Type for $serviceName set to $startupType.\"\n",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "Windows",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-service-set-startup-type.json",
  "Website": "/step-templates/361926f3-8c53-4d19-bb3b-337a531e4448",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Tuesday, September 16, 2014