﻿# 如何解決 WSL 2 底下無法執行 Windows 應用程式的問題 (run-detectors)

我最近經常在 WSL 2 環境下開發，這樣不但可以大幅減少電腦的各種複雜配置與相依問題，有時候執行速度甚至比 Windows 還快。但我其中一台電腦這幾天卻出現了個詭異問題，想要執行 `code .` 卻會出現 **run-detectors: unable to find an interpreter for /mnt/c/Program Files/Microsoft VS Code/Code.exe** 的錯誤訊息，無法成功啟動 VSCode 執行，找了好一會兒才解決。

### 問題發生原因

老實說，我並不清楚問題怎麼發生的，但我有整理幾個相關的 Issues 供未來研究：

-   microsoft/WSL
    -   [Can't open Windows app from WSL 2 anymore · Issue #4567](https://web.archive.org/web/20251231180034/https://github.com/microsoft/WSL/issues/4567)
    -   [Interop Issue: unable to find interpreter for launching Windows .exe files using Interop · Issue #5466](https://github.com/microsoft/WSL/issues/5466)
-   Reddit
    -   [Can't open Windows app from WSL 2 anymore. Please help me :( : bashonubuntuonwindows](https://www.reddit.com/r/bashonubuntuonwindows/comments/dc8x6k/cant_open_windows_app_from_wsl_2_anymore_please/)
-   StackExchange
    -   [wine - unable to find an interpreter when running a Windows executable - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/159193/unable-to-find-an-interpreter-when-running-a-windows-executable)

### 解決方案

網路上找到幾種解決方案，供各位參考，我自己是透過下列第 1 種解決方案搞定問題的！

1.  在 WSL 2 的 Shell 中執行以下命令
    
    ```bash
    sudo update-binfmts --disable cli
    ```
    
2.  在 Command Prompt (命令提示字元) 執行以下命令
    
    ```bash
    wsl --shutdown
    ```
    
    > 注意：上述命令將會關閉「所有」正在執行中的 WSL Distros！
    

### 相關連結

-   [Using WSL 2 with Visual Studio Code](https://code.visualstudio.com/blogs/2019/09/03/wsl2)
-   [Announcing WSL 2 | Windows Command Line](https://devblogs.microsoft.com/commandline/announcing-wsl-2/)
-   [Windows interoperability with Linux | Microsoft Docs](https://learn.microsoft.com/en-us/windows/wsl/interop)
