Windows-Sandbox icon indicating copy to clipboard operation
Windows-Sandbox copied to clipboard

[Bug]: Automatically restarting a sandbox while it is minimized can sometimes freeze the host machine

Open DaisukeDaisuke opened this issue 9 months ago • 0 comments

Windows Sandbox version

0.5.0.0

Windows build number

Microsoft Windows [Version 10.0.26100.3775]

Other software

Google Chrome

Steps to reproduce the bug

Run Restart-Computer when Windows Sandbox is not in the foreground

<Configuration>
    <Networking>Disable</Networking>
    <MappedFolders>
        <MappedFolder>
            <HostFolder>d:\drivers\</HostFolder>
            <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Sandbox-Files\</SandboxFolder>
            <ReadOnly>true</ReadOnly>
        </MappedFolder>
        <MappedFolder>
            <HostFolder>d:\drivers\data\</HostFolder>
            <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Data\</SandboxFolder>
            <ReadOnly>false</ReadOnly>
        </MappedFolder>
        <MappedFolder>
            <HostFolder>C:\Users\testuser\Videos\</HostFolder>
            <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\Videos\</SandboxFolder>
            <ReadOnly>false</ReadOnly>
        </MappedFolder>
    </MappedFolders>
    <vGPU>Enable</vGPU>
    <MemoryInMB>32784</MemoryInMB>
    <LogonCommand>
        <Command>powershell -executionpolicy unrestricted -command "start powershell {-file "C:\Users\WDAGUtilityAccount\Desktop\Sandbox-Files\general\general.ps1"}"</Command>
    </LogonCommand>
    <AudioInput>Disable</AudioInput>
    <VideoInput>Disable</VideoInput>
</Configuration>
$path = "C:\Users\WDAGUtilityAccount"

if (!(Test-Path -Path $path -PathType Container)) {
    Write-Error "Error: Required directory '$path' not found."
    exit 1
}

$path1 = "C:\Windows\Temp\KJFLSH.txt"

if ((Test-Path -Path $path1 -PathType Leaf)) {
    exit 1
}

New-Item -Path $path1 -ItemType File -Force | Out-Null

$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8

# 右クリックをWindows10以前のものに戻す
reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /ve /d "" /f
# タスクバーを左揃えにする
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "TaskbarAl" /t REG_DWORD /d "0" /f
# 拡張子を常に表示
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "HideFileExt" /t REG_DWORD /d "0" /f
# すべてのフォルダーを表示
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "NavPaneShowAllFolders" /t REG_DWORD /d "1" /f
# タイトルバーに完全なパスを表示
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState" /v "FullPath" /t REG_DWORD /d "1" /f
#  Windows を最大限に活用するためのデバイス設定の完了方法を提案する 「オフ」
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement" /v "ScoobeSystemSettingEnabled" /t REG_DWORD /d 0 /f
#  Windows を使う上でのヒントやお勧めの方法を取得する 「オフ」
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /v "SubscribedContent-338389Enabled" /t REG_DWORD /d 0 /f
# 新機能とおすすめを確認するために~をオフ
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /v "SubscribedContent-310093Enabled" /t REG_DWORD /d "0" /f
# シフトを連打すると出てくる固定キーを無効化(上のように再起動がいる)
reg add "HKCU\Control Panel\Accessibility\StickyKeys" /v Flags /t REG_SZ /d "506" /f


# Explorerの再起動
Stop-Process -Name explorer -Force


Write-Output "install vc_redist.x64.exe`n"
powershell -ExecutionPolicy Unrestricted -File "C:\Users\WDAGUtilityAccount\Desktop\Sandbox-Files\vclib.ps1"


Write-Output "Installing vscode`n"
Start-Process -FilePath "C:\Users\WDAGUtilityAccount\Desktop\Sandbox-Files\VSCodeUserSetup-x64-1.96.4.exe" `
    -ArgumentList "/VERYSILENT /NORESTART /MERGETASKS=!runcode,desktopicon,addcontextmenufiles,addcontextmenufolders,associatewithfiles" `
    -NoNewWindow -Wait
Write-Output "VSCode installation completed."

Write-Output "vscode setting`n"

$settingsPath = "C:\Users\WDAGUtilityAccount\AppData\Roaming\Code\User\settings.json"

# 設定する内容
$jsonContent = '{
    "editor.unicodeHighlight.ambiguousCharacters": false,
    "editor.unicodeHighlight.invisibleCharacters": false,
    "editor.unicodeHighlight.includeComments": false,
    "editor.unicodeHighlight.includeStrings": false,
    "editor.unicodeHighlight.nonBasicASCII": false,
    "files.autoSave": "afterDelay"
}'

# ディレクトリが存在しない場合は作成
$dir = Split-Path -Path $settingsPath -Parent
if (!(Test-Path $dir)) {
    New-Item -ItemType Directory -Path $dir -Force
}

# JSON ファイルを書き込み
$jsonContent | Set-Content -Path $settingsPath -Encoding UTF8

Write-Output "VSCode settings.json has been updated."

# 一部アプリの文字化け対策
# 文字化け対策したうえで、プログラムを起動する場合
# https://chatgpt.com/share/67ef189b-8e28-8013-a396-87ce6d2a8deb

Set-WinUserLanguageList -Force ja-JP      # 言語リストとプロパティを日本語に設定
Set-WinSystemLocale -SystemLocale ja-JP   # システムロケールを 日本 に変更
Set-WinUILanguageOverride -Language ja-JP # 表示言語と地域設定を 日本語 に変更
Set-WinHomeLocation 122                   # 国と地域を 日本 に変更
Restart-Computer                          # システムを再起動


Expected result

Windows Sandbox should restart normally without crashing the host machine

Actual result

The host machine crashes (freezes) every once in a while and all context on the host machine is lost

Included System Information

Intel i7 14700F GeForce RTX 4070 TI Super [Driver 576.02] windows 11 Memory 128GB 4800MT/s

DaisukeDaisuke avatar Apr 23 '25 07:04 DaisukeDaisuke