Rework DisableService() : write UserFlagService reg key even although service could not be disable

This commit is contained in:
Yorick Barbanneau 2018-04-01 00:07:42 +02:00
parent 745049551a
commit c107756bd5

View file

@ -457,7 +457,14 @@ function DisableService {
}
Stop-Service -InputObject $service -PassThru | Set-Service -StartupType disabled
Write-Host -ForegroundColor Green "done"
if ( $params.userService ) {
}
catch {
Write-Host -NoNewLine -ForegroundColor Red "`tError`n`t"
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
}
finally {
Write-host "Value : $($params.userService.getType())"
if ( $params.ContainsKey('userService') -and $params.userService -eq $true ) {
# For this kind of service, we need to add a key t create a user service
# Where user log-in.
AddRegKey @{
@ -467,11 +474,6 @@ function DisableService {
}
}
}
catch {
Write-Host -NoNewLine -ForegroundColor Red "`tError`n`t"
write-Host -ForegroundColor DarkRed $Error[0].Exception.Message
return
}
}
else {
Write-Host -ForegroundColor Red "`tError : No name or file for action $($MyInvocation.MyCommand.Name)"