Skip to content

Commit

Permalink
added Service removal to CleanInstall
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkChaos committed Jun 17, 2020
1 parent dba0825 commit 8be88c1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,23 @@ $scriptBlock = {
Write-Output "[$env:ComputerName]: Instance Name: [$instanceName]"
$serviceName = "{0}`${1}" -f $ServiceName.split('$')[0], $instanceName
}

Write-Output "[$env:ComputerName]: Attempting to locate [$ServiceName]"
$serviceObject = Get-WindowsService -ServiceName $ServiceName
# If the service does not exist and the installtion path can only be provided if the Install Service flag is passed.
if ($null -eq $serviceObject -and $null -ne $installationPath) {
Write-Output "[$env:ComputerName]: Unable to locate [$ServiceName] creating a new service"
# If the service does not exist or cleanInstall is enabled and the installtion path can only be provided if the Install Service flag is passed.
if (($null -eq $serviceObject -or $CleanInstall) -and $null -ne $installationPath) {
if ($serviceObject) {
Write-Output "[$env:ComputerName]: Clean install set to [$CleanInstall], removing the Service [$ServiceName]"

$serviceObject = Stop-WindowsService -ServiceName $ServiceName

$serviceObject.Delete()
Write-Output "[$env:ComputerName]: Removed Service [$ServiceName]"
}
else {
Write-Output "[$env:ComputerName]: Unable to locate [$ServiceName] creating a new service"
}

if ($installTopShelfService) {
$parentPath = Get-FullExecuteablePath -StringContainingPath $installationPath -JustParentPath
if (-not(Test-Path $parentPath)) {
Expand Down
4 changes: 2 additions & 2 deletions WindowsServiceManager/WindowsServiceManagerV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 4,
"Minor": 4,
"Patch": 0
"Patch": 1
},
"instanceNameFormat": "Deploy Windows Service",
"groups": [
Expand Down Expand Up @@ -101,7 +101,7 @@
"label": "Service Description",
"defaultValue": "",
"required": false,
"helpMarkDown": "The Displayname of the windows service."
"helpMarkDown": "The Description of the windows service."
},
{
"name": "ServiceStartupType",
Expand Down
7 changes: 3 additions & 4 deletions WindowsServiceManager/WindowsServiceManagerV4/utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Get-WindowsService {
(
$ServiceName
)
Get-WmiObject -Class Win32_Service | Where-Object { $PSItem.Name -eq $ServiceName }
return Get-WmiObject -Class Win32_Service | Where-Object { $PSItem.Name -eq $ServiceName }
}

function Start-WindowsService {
Expand Down Expand Up @@ -63,7 +63,7 @@ function Stop-WindowsService {
if ($StopProcess) {
Write-Verbose "[$env:ComputerName]: [$ServiceName] did not respond within [$Timeout] seconds, stopping process."

$fullPath = Get-FullExecuteablePath -StringContainingPath $serviceObject.PathName
$parentPath = Get-FullExecuteablePath -StringContainingPath $serviceObject.PathName -JustParentPath

$allProcesses = Get-Process
$process = $allProcesses | Where-Object { $_.Path -like "$parentPath\*" }
Expand All @@ -81,9 +81,8 @@ function Stop-WindowsService {
while ($serviceObject.State -ne 'Stopped')

Write-Output "[$env:ComputerName]: Stopped Service [$ServiceName]"

return $serviceObject
}
return $serviceObject
}

function Get-FullExecuteablePath {
Expand Down

0 comments on commit 8be88c1

Please sign in to comment.