@@ -1362,12 +1362,6 @@ begin
13621362 end ;
13631363 end ;
13641364
1365- if IsNotBackgroundUpdate() and CheckForMutexes(' {#TunnelMutex}' ) then
1366- begin
1367- MsgBox(' {#NameShort} is still running a tunnel. Please stop the tunnel before installing.' , mbInformation, MB_OK);
1368- Result := false
1369- end ;
1370-
13711365end ;
13721366
13731367function WizardNotSilent (): Boolean;
@@ -1380,6 +1374,31 @@ end;
13801374var
13811375 ShouldRestartTunnelService: Boolean;
13821376
1377+ function StopTunnelOtherProcesses (): Boolean;
1378+ var
1379+ WaitCounter: Integer;
1380+ TaskKilled: Integer;
1381+ begin
1382+ Log(' Stopping all tunnel services (at ' + ExpandConstant(' "{app}\bin\{#TunnelApplicationName}.exe"' ) + ' )' );
1383+ ShellExec(' ' , ' powershell.exe' , ' -Command "Get-WmiObject Win32_Process | Where-Object { $_.ExecutablePath -eq ' + ExpandConstant(' '' {app}\bin\{#TunnelApplicationName}.exe'' ' ) + ' } | Select @{Name='' Id'' ; Expression={$_.ProcessId}} | Stop-Process -Force"' , ' ' , SW_HIDE, ewWaitUntilTerminated, TaskKilled)
1384+
1385+ WaitCounter := 10 ;
1386+ while (WaitCounter > 0 ) and CheckForMutexes(' {#TunnelMutex}' ) do
1387+ begin
1388+ Log(' Tunnel process is is still running, waiting' );
1389+ Sleep(500 );
1390+ WaitCounter := WaitCounter - 1
1391+ end ;
1392+
1393+ if CheckForMutexes(' {#TunnelMutex}' ) then
1394+ begin
1395+ Log(' Unable to stop tunnel processes' );
1396+ Result := False;
1397+ end
1398+ else
1399+ Result := True;
1400+ end ;
1401+
13831402procedure StopTunnelServiceIfNeeded ();
13841403var
13851404 StopServiceResultCode: Integer;
@@ -1413,7 +1432,11 @@ function PrepareToInstall(var NeedsRestart: Boolean): String;
14131432begin
14141433 if IsNotBackgroundUpdate() then
14151434 StopTunnelServiceIfNeeded();
1416- Result := ' '
1435+
1436+ if IsNotBackgroundUpdate() and not StopTunnelOtherProcesses() then
1437+ Result := ' {#NameShort} is still running a tunnel process. Please stop the tunnel before installing.'
1438+ else
1439+ Result := ' ' ;
14171440end ;
14181441
14191442// VS Code will create a flag file before the update starts (/update=C:\foo\bar)
@@ -1607,4 +1630,4 @@ begin
16071630 #endif
16081631
16091632 Exec(ExpandConstant(' {sys}\icacls.exe' ), ExpandConstant(' "{app}" /inheritancelevel:r ' ) + Permissions, ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode);
1610- end ;
1633+ end ;
0 commit comments