Skip to content

Commit d0b0659

Browse files
authored
Use wsb command to stop sandbox if possible (#382364)
1 parent 2116852 commit d0b0659

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Tools/SandboxTest.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,18 @@ foreach ($dependency in $script:AppInstallerDependencies) {
681681
}
682682

683683
# Kill the active running sandbox, if it exists, otherwise the test data folder can't be removed
684-
Stop-NamedProcess -ProcessName 'WindowsSandboxClient'
685-
Stop-NamedProcess -ProcessName 'WindowsSandboxRemoteSession'
684+
if (Get-Command wsb -ErrorAction SilentlyContinue) {
685+
$sandboxInstance = @(wsb list) | Select-Object -First 1
686+
if ($sandboxInstance) {
687+
wsb stop --id $sandboxInstance
688+
} else {
689+
Write-Verbose 'No running instance of Sandbox'
690+
}
691+
} else {
692+
Write-Debug 'wsb command was not found - terminaing any sessions by process name'
693+
Stop-NamedProcess -ProcessName 'WindowsSandboxClient'
694+
Stop-NamedProcess -ProcessName 'WindowsSandboxRemoteSession'
695+
}
686696
Start-Sleep -Milliseconds 5000 # Wait for the lock on the file to be released
687697

688698
# Remove the test data folder if it exists. We will rebuild it with new test data

0 commit comments

Comments
 (0)