vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

`Code.exe: Invalid argument` after upgrading to Windows 11

Open ghost opened this issue 3 years ago • 31 comments

  • VSCode Version: 1.70.1
  • Local OS Version: Windows 11 21H2 22000.856
  • Remote OS Version: Ubuntu 20.04.4 LTS (WSL2)
  • Remote Extension/Connection Type: WSL

Steps to Reproduce:

  1. Ignore Windows 11 upgrade prompts for ages
  2. Upgrade to Windows 11
  3. Open terminal in WSL2 linux distro
  4. Navigate to a repo
  5. Type code . to launch VSCode

What you expected to see:

VSCode opens in remote mode

What you saw instead:

$ code .
/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code/Code.exe: Invalid argument

Notes

  • Opening VSCode directly and connecting to remote works fine
  • Opening VSCode in Windows (non-remote), uninstalling and re-installing the Remote - WSL extension fixes the issue temporarily. But when I restart my computer the problem returns. All the evidence I've found online suggests this fix and I was hopeful but for some reason it doesn't persist after a reboot.

I appreciate there's not a lot of info here. Please let me know what I can do to help troubleshoot this further.

ghost avatar Aug 11 '22 15:08 ghost

This seems to have fixed itself 🤷‍♂️ I have no idea what changed so can't provide further context but going to close this now.

ghost avatar Aug 18 '22 07:08 ghost

This issue has re-appeared again, seemingly after another restart. Happy to help debug this in any way I can.

ghost avatar Aug 24 '22 08:08 ghost

I just migrated to Windows 11 and see the exact same issue.

I migrated my entire WSL from my older laptop using it's export/import feature and installed a fresh copy of Visual Studio Code along with WSL extension and now can't get this very important feature, for me, working. See screenshot below

image

kp1dell avatar Mar 10 '23 14:03 kp1dell

In my case, this was related to this WSL issue, and the suggestion to wsl --shutdown from the windows command prompt fixed my issue at least temporarily. (After starting wsl again, code works as expected again.) However, it does seems to break again sometimes, and I don't see a consistent pattern with what causes it to break.

teichert avatar Mar 27 '23 21:03 teichert

This is also consistently happening to me as well. On Windows 11, new computer, not and upgrade. It isn't just code . that doesn't work. Similar commands like explorer.exe . give the same error.

wsl --shutdown works for a little bit but it always breaks again.

revoyrm avatar Jul 13 '23 19:07 revoyrm

suffering from this since windows 11 update. no idea what to do

apkatsikas avatar Aug 11 '23 14:08 apkatsikas

suffering from this since windows 11 update. no idea what to do

my solution was to uninstall/reinstall vscode. hopefully it lasts

apkatsikas avatar Aug 11 '23 14:08 apkatsikas

I have the same issue as reported here. For me wsl --shutdown resolved the problem. (Windows 11 version 10.0.22621)

I am using VS Code:

1.81.1
6c3e3dba23e8fadc360aed75ce363ba185c49794
x64

WSL distro:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

yooakim avatar Aug 15 '23 08:08 yooakim

Imho, this is not due to a Windows 11 upgrade but a WSL update: it happens to me frequently on Win 10, too. And "frequently" really means that it works at first for a few minutes/hours/... and then out of a sudden stops to work. Annoying! Btw, in my impression everything™ under /mnt/c/ is not working from there onwards (had my AZ CLI installed in Windows instead of WSL, failing too)

GraueEminenz79 avatar Aug 17 '23 06:08 GraueEminenz79

im not using windows 11 but had to reinstall it again Ubuntu 20.04, and when type code . gives me

/mnt/c/Users/leand/AppData/Local/Programs/Microsoft VS Code/Code.exe: Invalid argument

I've tried the wsl --shutdown command but it continues the same, and even trying to reload WSL extension, so the only way i can is opening VSCode and acessing host from there

leandroauzier avatar Nov 15 '23 19:11 leandroauzier

this issue still persist till today, need a follow up, anyone?

abdullzz avatar Dec 01 '23 03:12 abdullzz

Strange thing is, it works when i navigate to the program folder and then execute the program. But when i execute the program from another folder with absolute program path, it doesn't. By the way it is not only with vscode but every windows program which is mounted in WSL

ghost avatar Jan 02 '24 11:01 ghost

I'm also experiencing the same problem, wsl --shutdown has yet to resolve the issue

lulzhipsters avatar Jan 12 '24 04:01 lulzhipsters

Using W11 updated as of last week. For me the issue was WSL had to have administrator privileges. Without it, the same error occurred, with it the command code works. My guess is that something during VSCode installation made it administrator only, which impedes wsl to access it without such privileges.

peterhbg avatar Jan 16 '24 15:01 peterhbg

This worked for me as of this writing:

  1. Reinstall VSCode (latest version)
  2. Ran wsl --shutdown
>wsl --version
WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59

hmenorjr avatar Jan 22 '24 13:01 hmenorjr

The issue was resolved for me when turned off "Run As Admin"

image

image

chazwilder avatar Feb 20 '24 13:02 chazwilder

I also had this problem, I had success with running wsl --shutdown + start WSL as administrator 🤔

divinity76 avatar Mar 19 '24 06:03 divinity76

Same problem

tutunak avatar Mar 20 '24 17:03 tutunak

i forgot to mention that the palliative measure that i found was to remove vscode-server and shutdown wsl:

rm -r ~/.vscode-server then on cmd or powershell: wsl --shutdown

and then boot again with code . command to reinstall vscode

leandroauzier avatar Mar 20 '24 22:03 leandroauzier

The issue was resolved for me when turned off "Run As Admin"

image

image

It does work well, thx!!!

sherlockyzd avatar Apr 02 '24 09:04 sherlockyzd

Just running the wsl terminal (Ubuntu) as administrator fixed the issue for me. you can temporarily right click on the app and run as administrator or for permanent solution go to the WSL folder on this path: C:\Program Files\WSL and make the wsl.exe file to always run as administrator from the compatibility tab check the image below

wsl

Specifications:

WSL version: 2.1.5.0 Distro: Ubuntu-22.04 Kernel version: 5.15.146.1-2 OS: Windows_NT x64 10.0.19045

AhmadYousif89 avatar Apr 04 '24 13:04 AhmadYousif89

The issue was resolved for me when turned off "Run As Admin"

image

image

It works for me, thanks!

MatchalatteR avatar Apr 15 '24 02:04 MatchalatteR

O problema foi resolvido para mim quando desativei "Executar como administrador"

imagem

imagem

Thank you, works here

andersonlobo98 avatar Apr 18 '24 14:04 andersonlobo98

Fixed the problem with opening ubuntu in administrator hope it works for you too but I downloaded ubuntu through wsl than restarted it than administrator part just in case.

seojunchian avatar May 23 '24 10:05 seojunchian

Any other solution beisdes running vscode as an admin? in most corp, the admin option is not a solution.

habsfanongit avatar Oct 04 '24 18:10 habsfanongit

The root cause of this issue lies in the permission management and process isolation mechanisms between Windows and WSL. When you run code.exe as an administrator, processes running as a regular user in WSL cannot interact with the elevated process. This leads to the code command in WSL failing to start Visual Studio Code correctly.

Detailed Explanation

  1. Permission Isolation: In Windows, there is permission isolation between processes running as an administrator and those running as a regular user. Regular user processes cannot directly interact with administrator processes. This is a security measure to prevent unauthorized operations by regular user processes.

  2. WSL and Windows Process Interaction: Processes in WSL typically run with regular user permissions. When you run the code . command in WSL, it attempts to start a new code.exe process. If code.exe is already running as an administrator, the regular user process in WSL cannot interact with this elevated process, leading to the error.

Solutions

To avoid this issue, you can choose from the following solutions:

  1. Do Not Run VS Code as Administrator: Ensure that code.exe is not running as an administrator. This way, regular user processes in WSL can start and interact with code.exe normally.

  2. Run WSL as Administrator: If you need to run VS Code as an administrator, you can try running WSL as an administrator. This can be done with the following steps:

    • Right-click the Windows Start menu and select "Windows PowerShell (Admin)" or "Command Prompt (Admin)".
    • Start WSL from the elevated PowerShell or Command Prompt:
      wsl
      
    • Now run the code . command in WSL.
  3. Use VS Code Remote - WSL Extension: This extension allows you to seamlessly use VS Code within WSL without worrying about permission issues. Ensure you have installed VS Code and the Remote - WSL extension, then run the following command in WSL:

    code .
    

    This will start VS Code and connect to the WSL environment.

By following these methods, you should be able to avoid permission issues and use the code command in WSL without any problems.

vkviyu avatar Oct 05 '24 20:10 vkviyu

关闭“以管理员身份运行”后,此问题已为我解决

image

image

The issue was resolved for me when turned off "Run As Admin"

image

image

This works in mine.As the saying goes :“Every cause has its effect.”A few days ago I ticked exactly this Run-As-Admin-option in order to install an extension for VSCode. If this solution holds true for you as well, in order to permanently solve similar possible problems, I would suggest that you assign permissions to the root directory where VSCode is located (e.g., 'D:\Program Files') to your usual users instead of just administrators (of course, you need to make sure that you know what you're doing).

DJ-Yosef avatar Nov 12 '24 21:11 DJ-Yosef

same issue in 2025/05/06

jokerknight avatar May 06 '25 11:05 jokerknight

Same issue

Xarnattos avatar Jul 10 '25 02:07 Xarnattos