WSL Commands to Access Windows Resources

This blog post describes Windows Subsystem for Linux (WSL) tools that retrieve variables from Windows and convert between Windows and Unix file system paths.

Screen capture of console output from wsl* commands

I typed wsl and pressed tab twice on an empty line in a shell and got a list of commands that start with wsl. The wslupath and wslvar commands are useful for retrieving environment variables and values for other settings from Windows. The wslpath command is useful for converting between Windows and Unix file system paths. You can get information about each command by invoking it with the -h argument. Excluding wslpath and commands that end with the .exe extension, these appear to be components of the Windows Subsystem Utilities collection that apparently ships with WSL, at least my Ubuntu 20.04 LTS installation. You can use man <command> to get additional details about these commands. You can also read these shell scripts in a text editor. Note that these scripts may use winps_exec that invokes Windows PowerShell.

  • wsl.exe: Launches a WSL shell.
  • wslconfig.exe: Lists, set the default, terminates, and unregisters WSL Linux distributions.
  • wslpath: Convert between Windows and Linux paths.
  • wslupath: Output the directory path to the Desktop, %APPDATA%, temp, system, Start menu, Startup directory, %HOMEPATH%, and %ProgramFiles% directory associated with the current Windows user.
  • wslvar: Output Windows variables (shell folders as well as global and local environment variables).
  • wslapi.dll: Ignore
  • wslfetch: Displays information about WSL in use.
  • wslsys: Output information about WSL in use.
  • wslusc: Creates Windows shortcuts.

You can use the wslupath command with the -s argument to get the Linux path to the Start Menu directory for the current Windows user.

startmenu=`wslupath -s` ; echo $startmenu

You can use the wslvar command with the –getshell and –getsys arguments to list available values.

wslvar --getshell ; echo "" ; wslvar --getsys

For me, the Shell list includes:

  • AppData
  • Cache
  • Cookies
  • Favorites
  • History
  • Local AppData
  • My Music
  • My Video
  • NetHood
  • PrintHood
  • Programs
  • Recent
  • SendTo
  • Start Menu
  • Startup
  • Templates
  • {374DE290-123F-4565-9164-39C4925E467B} (Downloads)
  • {A52BBA46-E9E1-435f-B3D9-28DAA648C0F6} (OneDrive)
  • Desktop
  • My Pictures
  • Personal
  • {F42EE2D3-909F-4907-8871-4C22FC0BF756} (Documents)
  • {0DDD015D-B06C-45D5-8C4C-F59713854639} (Pictures)

For me, the System list includes:

  • CommonProgramFiles
  • CommonProgramFiles(x86)
  • CommonProgramW6432
  • ComSpec
  • DriverData
  • OneDrive                     
  • OneDriveConsumer   
  • 0OS                           
  • Path                          
  • PATHEXT                  
  • PROCESSOR_LEVEL                                                                                                  
  • ProgramData                   
  • ProgramFiles                  
  • ProgramFiles(x86)            
  • ProgramW6432                
  • PSModulePath                  
  • PUBLIC                         
  • SESSIONNAME                   
  • SystemDrive                                                                                                      
  • SystemRoot                    
  • TEMP                          
  • TMP                           
  • USERDOMAIN          
  • USERNAME                                                                                       
  • USERPROFILE                    
  • windir                        
  • WSLENV                    
  • WT_PROFILE_ID      
  • WT_SESSION            
  • ZES_ENABLE_SYSMAN                                                                                                 

You can use the wslvar command with the –shell argument (not just -s) to name a shell variable to retrieve.

personal=`wslvar --shell Personal` ; echo $personal

You can use the wslvar command with the -l argument to name a local variable to retrieve.

startmenu=`wslvar --shell "Start Menu"` ; echo $startmenu

You can use the wslpath command to convert Windows file system paths to Linux file system paths.

startup=`wslvar -l Startup` ; startup=`wslpath "$startup"` ; echo $startup

One thought on “WSL Commands to Access Windows Resources

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: