Octopus.Script exported 2015-06-30 by jbennett belongs to ‘Windows’ category.
Uses regsvr32.exe to register com components
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
DllFilePaths
DllFilePaths
List of dlls to be registered separated by a ; and can appear on separate lines
Un-register
Uninstall
null
Script body
Steps based on this template will execute the following PowerShell script.
# Running outside octopus
param(
[string]$DllFilePaths,
[string]$Uninstall
)
$ErrorActionPreference = "Stop"
function Get-Param($Name, [switch]$Required, $Default) {
$result = $null
if ($OctopusParameters -ne $null) {
$result = $OctopusParameters[$Name]
}
if ($result -eq $null) {
$variable = Get-Variable $Name -EA SilentlyContinue
if ($variable -ne $null) {
$result = $variable.Value
}
}
if ($result -eq $null) {
if ($Required) {
throw "Missing parameter value $Name"
} else {
$result = $Default
}
}
return $result
}
& {
param(
[string]$DllFilePaths,
[string]$Uninstall
)
$isUninstall = $($Uninstall.ToLower() -eq 'true')
Write-Host "COM Component - Register"
Write-Host "DllFilePaths: $DllFilePaths"
$DllFilePaths.split(";") | ForEach {
$dllFilePath = $_.Trim();
Write-Host $dllFilePath
if($dllFilePath.Length -lt 1){
break;
}
Write-Host "Attempting to register $dllFilePath"
if(!(Test-Path "$dllFilePath"))
{
Write-Host "FILE NOT FOUND $dllFilePath." -ForegroundColor Yellow;
return;
}
Write-Host "Attempting to register $dllFilePath"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$cmd = "$env:windir\System32\regsvr32.exe"
Write-Host "Registering with: $env:windir\System32\regsvr32.exe"
$pinfo.FileName = "$cmd"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
if($isUninstall){
$args = "/u"
}
$args = "$args /s `"$dllFilePath`""
$pinfo.Arguments = $args
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
Write-Host "Command:"
Write-Host "$cmd $args"
if ($p.Start())
{
Write-Host $p.StandardOutput.ReadToEnd().ToString()
if($p.ExitCode -ne 0)
{
Write-Host "FAILED $($p.ExitCode) - Register" -ForegroundColor Red
Write-Host $p.StandardError.ReadToEnd() -ForegroundColor Red
throw $p.StandardError.ReadToEnd()
}
Write-Host "SUCCESS- Register" -ForegroundColor Green
}
}
} `
(Get-Param 'DllFilePaths' -Required) `
(Get-Param 'Uninstall' -Required)
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "cf8634b6-313f-4435-bae6-88520c58d81d",
"Name": "Com Component - Register and Unregister using Regsvr32.exe",
"Description": "Uses regsvr32.exe to register com components",
"Version": 2,
"ExportedAt": "2015-06-30T18:55:08.050+00:00",
"ActionType": "Octopus.Script",
"Author": "jbennett",
"Parameters": [
{
"Name": "DllFilePaths",
"Label": "DllFilePaths",
"HelpText": "List of dlls to be registered separated by a ; and can appear on separate lines",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "MultiLineText"
}
},
{
"Name": "Uninstall",
"Label": "Un-register",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "# Running outside octopus\nparam(\n [string]$DllFilePaths,\n [string]$Uninstall\n)\n\n$ErrorActionPreference = \"Stop\" \n\nfunction Get-Param($Name, [switch]$Required, $Default) {\n $result = $null\n\n if ($OctopusParameters -ne $null) {\n $result = $OctopusParameters[$Name]\n }\n\n if ($result -eq $null) {\n $variable = Get-Variable $Name -EA SilentlyContinue \n if ($variable -ne $null) {\n $result = $variable.Value\n }\n }\n\n if ($result -eq $null) {\n if ($Required) {\n throw \"Missing parameter value $Name\"\n } else {\n $result = $Default\n }\n }\n\n return $result\n}\n\n& {\n param(\n [string]$DllFilePaths,\n [string]$Uninstall\n ) \n\n $isUninstall = $($Uninstall.ToLower() -eq 'true')\n\n Write-Host \"COM Component - Register\"\n Write-Host \"DllFilePaths: $DllFilePaths\"\n\n $DllFilePaths.split(\";\") | ForEach {\n $dllFilePath = $_.Trim();\n Write-Host $dllFilePath\n \n if($dllFilePath.Length -lt 1){\n break;\n }\n \n Write-Host \"Attempting to register $dllFilePath\"\n\n if(!(Test-Path \"$dllFilePath\"))\n {\n Write-Host \"FILE NOT FOUND $dllFilePath.\" -ForegroundColor Yellow;\n return;\n }\n\n Write-Host \"Attempting to register $dllFilePath\"\n \n $pinfo = New-Object System.Diagnostics.ProcessStartInfo\n\n $cmd = \"$env:windir\\System32\\regsvr32.exe\"\n\n Write-Host \"Registering with: $env:windir\\System32\\regsvr32.exe\"\n\n $pinfo.FileName = \"$cmd\"\n\n $pinfo.RedirectStandardError = $true\n $pinfo.RedirectStandardOutput = $true\n $pinfo.UseShellExecute = $false\n \n if($isUninstall){\n $args = \"/u\"\n }\n $args = \"$args /s `\"$dllFilePath`\"\"\n\n $pinfo.Arguments = $args\n \n $p = New-Object System.Diagnostics.Process\n\n $p.StartInfo = $pinfo\n\n Write-Host \"Command:\"\n Write-Host \"$cmd $args\"\n\n if ($p.Start())\n {\n Write-Host $p.StandardOutput.ReadToEnd().ToString()\n\n if($p.ExitCode -ne 0)\n {\n \n Write-Host \"FAILED $($p.ExitCode) - Register\" -ForegroundColor Red \n Write-Host $p.StandardError.ReadToEnd() -ForegroundColor Red\n \n throw $p.StandardError.ReadToEnd()\n }\n \n Write-Host \"SUCCESS- Register\" -ForegroundColor Green \n }\n\n \n }\n\n } `\n (Get-Param 'DllFilePaths' -Required) `\n (Get-Param 'Uninstall' -Required)",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"Category": "Windows",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/com-component-register-unregister.json",
"Website": "/step-templates/cf8634b6-313f-4435-bae6-88520c58d81d",
"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"
}
}
Page updated on Tuesday, June 30, 2015