Skip to content

Commit cbb4712

Browse files
authored
cli: stop tunnel processes during update (microsoft#187738)
* untested wip * make it work
1 parent 87baaea commit cbb4712

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

build/gulpfile.vscode.win32.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ function buildWin32Setup(arch, target) {
9898
AppMutex: product.win32MutexName,
9999
TunnelMutex: product.win32TunnelMutex,
100100
TunnelServiceMutex: product.win32TunnelServiceMutex,
101+
TunnelApplicationName: product.tunnelApplicationName,
101102
ApplicationName: product.applicationName,
102103
Arch: arch,
103104
AppId: { 'ia32': ia32AppId, 'x64': x64AppId, 'arm64': arm64AppId }[arch],

build/win32/code.iss

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
13711365
end;
13721366
13731367
function WizardNotSilent(): Boolean;
@@ -1380,6 +1374,31 @@ end;
13801374
var
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+
13831402
procedure StopTunnelServiceIfNeeded();
13841403
var
13851404
StopServiceResultCode: Integer;
@@ -1413,7 +1432,11 @@ function PrepareToInstall(var NeedsRestart: Boolean): String;
14131432
begin
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 := '';
14171440
end;
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

Comments
 (0)