diff --git a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 index 2e2e0d7..10ed755 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/DeployWindowsService.ps1 @@ -153,10 +153,20 @@ $scriptBlock = { Write-Host "[$env:ComputerName]: Stopping the service [$ServiceName]" $serviceObject = Stop-WSMWindowsService -ServiceName $ServiceName Write-Host "[$env:ComputerName]: Deleting the service [$ServiceName]" - $deleteResults = $serviceObject.Delete() + + try { + $deleteResults = $serviceObject.Delete() + } + catch { + Write-Error "[$env:ComputerName]: Failing remove Service [$ServiceName]. Used ServiceObject [$serviceObject]" + Write-Error $_.Exception.Message + return + } + if($deleteResults.ReturnValue -eq 0) { Write-Host "[$env:ComputerName]: Successfully removed [$ServiceName]" + $serviceObject = $null } else { @@ -280,22 +290,7 @@ $scriptBlock = { } -if ($Machines) -{ - $newPSSessionSPlat = @{ - ComputerName = $Machines - SessionOption = $sessionOption - UseSSL = $UseSSL - } - if ($credential) - { - $newPSSessionSPlat.Credential = $credential - } - $sessions = New-PSSession @newPSSessionSPlat -} - $invokeCommandSplat = @{ - Session = $sessions ArgumentList = $ServiceName, $ServiceDisplayName, $ServiceDescription, @@ -315,8 +310,23 @@ $invokeCommandSplat = @{ $InstallService } -# Import utility script into session -Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH +if ($Machines) +{ + $newPSSessionSPlat = @{ + ComputerName = $Machines + SessionOption = $sessionOption + UseSSL = $UseSSL + } + if ($credential) + { + $newPSSessionSPlat.Credential = $credential + } + $sessions = New-PSSession @newPSSessionSPlat + $invokeCommandSplat.Session = $sessions + + # Import utility script into session + Invoke-Command @invokeCommandSplat -FilePath $UTILITY_PATH +} # Invoke script block Invoke-Command @invokeCommandSplat -ScriptBlock $scriptBlock diff --git a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 index 0797af1..fc3d5d9 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 +++ b/WindowsServiceManager/WindowsServiceManagerV5/ps_modules/WindowsServiceManagerPS/WindowsServiceManagerPS.ps1 @@ -89,7 +89,7 @@ SeServiceLogonRight = $($currentSetting) try { secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS - #write-host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " + #Write-Host "secedit.exe /configure /db ""secedit.sdb"" /cfg ""$($tmp2)"" /areas USER_RIGHTS " } finally { @@ -220,13 +220,16 @@ function Get-WSMFullExecuteablePath [switch] $JustParentPath = $false ) + Write-Verbose "StartCommand=[$StartCommand]" + Write-Verbose "StringContainingPath=[$StringContainingPath]" # pattern to analyse Service Startup Command $matchPattern = '( |^)(?([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄܰ^!§$%&=`´,;@#+._-]+)(.exe|.dll))|(( "|^")(?(([a-zA-Z]):\\([\\\w\/\(\)\[\]{}öäüÖÄܰ^!§$%&=`´,;@#+._ -]+)(.exe|.dll)))(" |"$))' # check if PathName can be processed - if ($StringContainingPath -notmatch $matchPattern) + #if ($StringContainingPath -notmatch $matchPattern) + if ($StartCommand -notmatch $matchPattern) #as workaround it will not be Used the parameter. The function Parameter always trims the Quotes. { - return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path ending with an '.exe' or '.dll'. Current string [$StringContainingPath]" + return Write-Warning -Message "String can't be parsed. The StringContainingPath parameter should contain a valid Path without spaces or wrapped in quotes and ending with an '.exe' or '.dll'. Current string [$StringContainingPath]" } # extract Path diff --git a/WindowsServiceManager/WindowsServiceManagerV5/task.json b/WindowsServiceManager/WindowsServiceManagerV5/task.json index 5dd3de7..80aa3b8 100644 --- a/WindowsServiceManager/WindowsServiceManagerV5/task.json +++ b/WindowsServiceManager/WindowsServiceManagerV5/task.json @@ -14,7 +14,7 @@ "version": { "Major": 5, "Minor": 0, - "Patch": 1 + "Patch": 5 }, "instanceNameFormat": "Deploy Windows Service", "groups": [ diff --git a/vss-extension.json b/vss-extension.json index 154c4a7..c0e4bb6 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -1,7 +1,7 @@ { "manifestVersion": 1, "id": "WindowsServiceManager", - "version": "5.0.3", + "version": "5.0.7", "name": "Windows Service Manager", "description": "Installs and deploys a windows service or TopShelf service on a target machine or a deployment group target.", "publisher": "MDSolutions",