@@ -1362,12 +1362,6 @@ begin
1362
1362
end ;
1363
1363
end ;
1364
1364
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
-
1371
1365
end ;
1372
1366
1373
1367
function WizardNotSilent (): Boolean;
@@ -1380,6 +1374,31 @@ end;
1380
1374
var
1381
1375
ShouldRestartTunnelService: Boolean;
1382
1376
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
+
1383
1402
procedure StopTunnelServiceIfNeeded ();
1384
1403
var
1385
1404
StopServiceResultCode: Integer;
@@ -1413,7 +1432,11 @@ function PrepareToInstall(var NeedsRestart: Boolean): String;
1413
1432
begin
1414
1433
if IsNotBackgroundUpdate() then
1415
1434
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 := ' ' ;
1417
1440
end ;
1418
1441
1419
1442
// VS Code will create a flag file before the update starts (/update=C:\foo\bar)
@@ -1607,4 +1630,4 @@ begin
1607
1630
#endif
1608
1631
1609
1632
Exec(ExpandConstant(' {sys}\icacls.exe' ), ExpandConstant(' "{app}" /inheritancelevel:r ' ) + Permissions, ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode);
1610
- end ;
1633
+ end ;
0 commit comments