How to launch the WSL Ubuntu "Console" from the command line
I'm struggling to launch the WSL "Ubuntu 20.04" Store App (or any Store App, really) from the command-line (e.g. PowerShell or CMD).
When I run Ubuntu 20.04 from the Start Menu, it launches in a window with the Ubuntu icon and the correct window title ("Ubuntu 20.04 LTS"). I'd like to get that same application window when launched from the command-line.
I've searched quite a bit, and found this page that references start shell:AppsFolder\{folder}!App
(e.g. start shell:AppsFolder\Microsoft.WindowsStore_8wekyb3d8bbwe!App
), but I haven't been able to make that work for the Ubuntu Store App. It seems a bit convoluted to me -- Is there an easier way? And if not, how does that work for Ubuntu?
I'm familiar with the wsl
command, but if I run wsl -d Ubuntu-20.04
from the Start Menu, the resulting window has the generic WSL/Linux/Penguin icon instead of the Ubuntu icon. The window title is also C:\Windows\system32\wsl.exe
instead of "Ubuntu 20.04 LTS."
If I run the same wsl
command from CMD, it still has the CMD icon.
Perhaps I could use the DOS/CMD TITLE
command, but I'd like to just have a command I can use to launch the Store app. Is this possible?
By contrast, "normal" .exe
Windows apps can be launched from CMD or PowerShell quite easily.
I'd be really happy with a solution for Ubuntu WSL, but also if there is simple (and notably, programmable) way to run all Windows Store Apps, that would be great.
Solution 1:
Providing this as a separate answer since, as you've noticed, App Execution Aliases (from my other answer) aren't created by all WSL distributions.
The page that you came across on how to use start shell:/AppsFolder...
is on the right track, but misses a key point -- The !App
at the end works for most but not all UWP/Store apps. I actually came across this last year when I was trying to back up my Minecraft Dungeons progress, oddly enough ...
The actual syntax is:
start shell:AppsFolder\PackageFamilyName!AppId
PackageFamilyName
typically matches the directory name in C:\Program Files\WindowsApps
, but that directory is not typically readable unless you have elevated your permissions via UAC.
And AppId
is the real challenge to find. It's defined in the XML manifest for the package. And it can be whatever the developer wants it to be. Most do use App
, but there are (especially for WSL, it seems) exceptions.
Here's a PowerShell snippet to run through all of your user's Appx packages (Store-installed as well as those that come with Windows) along with a few "system" packages:
Get-AppxPackage | ForEach-Object {
$packageFamilyName = $_.PackageFamilyName
$packageManifest = Get-AppxPackageManifest $_
$displayName = $packageManifest.Package.Properties.DisplayName
$appId = $packageManifest.Package.Applications.Application.Id
Write-Output "${displayName}: ${packageFamilyName}!${appId}"
}
-
Get-AppxPackage
: Enumerate the installed packages -
$_.PackageFamilyName
: Should match the directory name inC:\Program Files\WindowsApps
for most non-system packages -
Get-AppxPackageManifest
returns the XML package manifest for the app - Then we get the
DisplayName
andAppId
properties by traversing the XMLDocument as PowerShell/.Net properties.
You should be able to use the resulting output with the start
(CMD) or Start-Process
(PowerShell) a la:
start-process shell:AppsFolder\36828agowa338.AlpineWSL_my43bytk1c4nr!alpinewsl
But do, of course, check your actual output from the above Get-AppxPackage
test above, since the Family name can change based on the Store release, I believe.
For me, this launched a separate Windows Console with Alpine, with the Alpine logo and title.
Solution 2:
Short answer:
From CMD or PowerShell:
start ubuntu.exe
If start
isn't aliased under PowerShell, try:
start-process ubuntu.exe
More detail:
ubuntu.exe
is the "App Execution Alias" for the "Ubuntu" app installed from the Microsoft Store, although it's possible that it could also be:
-
ubuntu2004.exe
: If you installed the "versioned" "Ubuntu 20.04" from the Store -
ubuntu1804.exe
: If you installed the "versioned" "Ubuntu 18.04" - And I'll assume that you don't still have the deprecated 16.04 version around.
You can see this by going to Manage app execution aliases in Windows Settings. Many Store apps include a "fake .exe
" that is designed to launch the Store app. You can disable this, but I'm assuming it's enabled. If not, enable it, of course.
When you run Ubuntu from the Start Menu, it is, of course, running the Store app. This app runs WSL in the legacy Windows Console, and does a couple of additional things such as set the application icon and font. That's pretty much the only difference than I can find from running it from the command-line.
When you run ubuntu.exe
(or one of the other WSL app execution aliases) from the command-line, it is started in the current terminal. It's the same as typing ipconfig.exe
, for instance. It retains the current characteristics of the "owning" terminal (started by CMD or PowerShell) -- Same app icon, same fonts, etc.
When run with the start
(CMD) or Start-Process
(PowerShell) command, it starts a separate process in Windows (rather than as a subprocess of the current shell). Windows launches it in a new terminal (Windows Console by default), and presumably, WSL does some magic to say "if I'm the owner of the terminal, then set the icon and font".