Skip to content

Commit e8d3d4a

Browse files
Re-implemented force cleanup via AgentCleanup4
1 parent 6a25106 commit e8d3d4a

4 files changed

Lines changed: 37 additions & 7 deletions

File tree

Agent/AgentCleanup4.exe

27.5 KB
Binary file not shown.

Agent/InstallAgent.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ $Script = @{
612612
"Library" = @($SC.Paths.TempFolder, "Lib") -join '\'
613613
"PartnerFile" = @($SC.Paths.TempFolder, $SC.Names.PartnerConfig) -join '\'
614614
"TempFolder" = $SC.Paths.TempFolder
615+
"AgentCleanup" = @($SC.Paths.TempFolder, "AgentCleanup4.exe") -join '\'
615616
}
616617
"Results" = @{
617618
"EventLog" = $SC.ScriptEventLog

Agent/Lib/InstallAgent-Core.psm1

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }

Agent/PartnerConfig.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ help@mymsp.com
3939
<!-- [REQUIRED - (1-60)] Amount of time (in minutes) to wait for the Windows Installer Service
4040
while another installation is in progress -->
4141
<InstallTimeoutPeriod>5</InstallTimeoutPeriod> <!-- Default Value is 5 -->
42+
<!-- [RECOMMENDED - (True)] - If there are issues with the MSI uninstall of the previous version, perform a cleanup -->
43+
<ForceAgentCleanup>True</ForceAgentCleanup>
4244
</ScriptBehavior>
4345
<Server>
4446
<!-- [REQUIRED - (URL Without Protocol)] Your N-Central Server Address (get this from the

0 commit comments

Comments
 (0)