Lxrun is not recognized as an internal or external command operable program or batch file

The most common reason why a command which runs an executable program works on the command line, but not in a batch script, is that, in the script, prior to the line containing the problem command, the user has created a variable %path%. It might seem a handy name for a variable that holds, well, a path. The problem is that this variable name is used by Windows to hold a semicolon-separated list of folders which are searched when an executable is called. It is a system variable. If you have redefined it, then all executables (e.g. .exe, .bat, .vbs, etc) that Windows uses, will not be found, and the script will fail with exactly this message, where xxx is the program or file that is expected:

'xxx' is not recognized as an internal or external command, operable program or batch file.

This can be confusing because commands which are internal to the cmd environment (dir, cls, set, copy, move, etc) (list here) still continue to work in this situation.

You can debug a script where this is suspected by inserting the path command immediately before a problem line. The Windows path variable starts with these folders, and may be extended as programs are installed:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

The problem is described in more detail in the link below and there are a tons of posts in this thread but it was an arduous process and there wasn’t a lot of other information about this problem so I figured I would write up a quick summary of how to fix this for the case where the instructions aren’t quite enough.

https://github.com/Microsoft/WSL/issues/473#issuecomment-224422589

Bascially, you need to run the lxrun command to reset Windows subsystem for Linux. The intructions were basically the following.

lxrun /uninstall /full /y
Reboot
Open an admin prompt or through explorer, delete all the content under the %localappdata%\lxss directory.
Install using bash.exe or "LxRun.exe /install"

However, something strange happened and every time I tried to do this I got a neat little error.

PS C:\Users\jmreicha\AppData\Local> LxRun /install /y
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

This will install Ubuntu on Windows, distributed by Canonical and licensed under its terms available here:
https://aka.ms/uowterms

Error: 0x80070005

Likewise, I couldn’t reinstall the Windows subsystem using other methods, I just got the same exact error. I was poking around a little bit more and found that the files the subsystem uses get saved off into %localappdata%\lxss. By default this directory isn’t displayed in Windows so in order to see this folder you need to uncheck the “Hide protected operating system files (Recommended)” option in Windows Explorer View Options.

Lxrun is not recognized as an internal or external command operable program or batch file

After showing OS files I was able to see the lxss directory and so I tried to delete the files, but got an interesting error message saying the files were no longer there and that Windows couldn’t remove them.

Lxrun is not recognized as an internal or external command operable program or batch file
Item Not Found

The only way I found to get around this problem was to rename the folder (hence the _old suffix in the screen shot).

After moving the directory to another name I was able to run the lxrun /install command and successfully reinstall Ubuntu.

PS C:\Users\jmreicha\AppData\Local> LxRun /install
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

This will install Ubuntu on Windows, distributed by Canonical and licensed under its terms available here:
https://aka.ms/uowterms

Type "y" to continue: y
Downloading from the Microsoft Store... 100%
Extracting filesystem, this will take a few minutes...

Conclusion

I saw various renditions of the solution sprinkled around the internet but none of them seemed to mention how to handle the case where Windows couldn’t locate a file and therefore couldn’t actually delete the lxss directory and recreate everything.

I haven’t figured out how to hard delete everything in the newly renamed “lxss_old” directory, so if anyone has any input it would be appreciated. As far as I know its contents are still consuming some amount of space on the system.

Josh is the creator of this blog, a system administrator and a contributor to other technology communities such as /r/sysadmin and Ops School. You can also find him on Twitter and Facebook.

How do I enable WSL2 in Windows 10?

Install WSL2 on Windows 10 1909 or older.
Open Start on Windows 10..
Search for Turn Windows features on or off and click the top result to open the experience..
Check the “Windows Subsystem for Linux” option..
Click the OK button..
Click the Restart button..

How do I fix Windows Subsystem for Linux has no installed distributions?

To update the Windows Subsystem for Linux itself, use the command wsl --update in PowerShell or CMD. To update the specific Linux distribution user binaries, use the command: apt-get update | apt-get upgrade in the Linux distribution that you are seeking to update.

What is LxRun EXE?

LxRun.exe, also known as a Microsoft Lxss Subsystem Tool file, was created by Microsoft for the development of Microsoft® Windows® Operating System. EXE files fall under under the Win64 EXE (Executable application) file type category.

How do I enable and install WSL in Windows 10?

Step 1 - Enable the Windows Subsystem for Linux..
Step 2 - Check requirements for running WSL 2..
Step 3 - Enable Virtual Machine feature..
Step 4 - Download the Linux kernel update package..
Step 5 - Set WSL 2 as your default version..
Step 6 - Install your Linux distribution of choice..
Troubleshooting installation..