@@ -679,6 +679,7 @@ function ValidatePartnerConfig {
679679 $Config.NETVersion = $InstallInfo.NETVersion
680680 $Config.NETFileVersion = $InstallInfo.NETFileVersion
681681 $Config.EnforceBehaviorPolicy = $Partner.Config.ServiceBehavior.EnforcePolicy
682+ $Config.ForceAgentCleanup = $Partner.Config.ScriptBehavior.ForceAgentCleanup
682683
683684 # ## Function Body
684685 # ##############################
@@ -2982,13 +2983,39 @@ function RemoveAgent {
29822983 # Verify Removal was Successful
29832984 DiagnoseAgent - NoLog - NoServerCheck
29842985 if ($Agent.Health.Installed -eq $true ) {
2985- # Exit - Agent Removal Failed
2986- FixServices - Restart
2987- $Out = (
2988- " MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
2989- " Manual forcible removal is required for the Script to continue."
2990- )
2991- Log E 11 $Out - Exit
2986+
2987+ # If the forced removal of the agent is enabled
2988+ if ($Config.ForceAgentCleanup ) {
2989+ $FAC = New-Object System.Diagnostics.ProcessStartInfo ($env: windir + " \system32\cmd.exe" )
2990+ $FAC.UseShellExecute = $false
2991+ $FAC.CreateNoWindow = $true
2992+ $FAC.Arguments = (' /C "' + $Script.Path.AgentCleanup + ' "' )
2993+ # Run the forced cleanup
2994+ [System.Diagnostics.Process ]::Start($FAC ).WaitForExit() > $null
2995+
2996+ # Verify Removal was Successful again
2997+ DiagnoseAgent - NoLog - NoServerCheck
2998+
2999+ if ($Agent.Health.Installed -eq $true ) {
3000+ # Exit - Agent Removal Failed
3001+ FixServices - Restart
3002+ $Out = (
3003+ " Forced and MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
3004+ " Manual forcible removal is required for the Script to continue."
3005+ )
3006+ Log E 11 $Out - Exit
3007+ }
3008+ } else {
3009+ # Exit - Agent Removal Failed
3010+ FixServices - Restart
3011+ $Out = (
3012+ " MSI Removal of the existing " + $NC.Products.Agent.Name + " failed. " +
3013+ " Manual forcible removal is required for the Script to continue."
3014+ )
3015+ Log E 11 $Out - Exit
3016+ }
3017+ # If forced removal successful, flag existing agent removal as true
3018+ $Install.ExistingAgentRemoved = $true
29923019 }
29933020 else
29943021 { $Install.ExistingAgentRemoved = $true }
0 commit comments