Windows Subsystem for Linux desktop shortcut to GUI

10,465

Why didn't I think of that?

This is one of those solutions where you look at it and think "Why didn't I think of that?". Unfortunately I had to look at many websites with wrong suggestions or over-kill such as "how to use regedit to run shortcut as admin".

Having the right parameters

Right click on your Windows 10 desktop and setup your shortcut to look like this:

Windows 10 shortcut properties

The full line for the Target field should look like this:

C:\Windows\System32\bash.exe -c "cd && DISPLAY=:0 /mnt/e/bin/lock-screen-timer"

NOTE: Most users will use /mnt/c/.... as their path but I'm dual-booting and the same script is shared by WSL and Ubuntu 16.04 so must be on a separate NTFS partition I've called /mnt/e. WSL cannot write to a Linux ext4 drive and Linux nor Windows Apps can write to a WSL sub-directory. It's complicated...

Also note the DISPLAY=:0 parameter accommodates calling a bash GUI script but the same is likely true if calling gedit or nautilus which are my next desktop shortcut projects. If not, I'll revise this answer..

Click the Change Icon button to get a default list of icons to choose from. This is where the clock icon came from.

Share:
10,465

Related videos on Youtube

WinEunuuchs2Unix
Author by

WinEunuuchs2Unix

Software development is my main hobby. Check out the new websites created in October 2021: www.pippim.com and pippim.github.io

Updated on September 18, 2022

Comments

  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 1 year

    I have a bash script called lock-screen-timer which calls yad to mount a GUI dialog box. Under Windows 10 and the Windows Subsystem for Linux (WSL) I can run it from the bash prompt (note VcXsrv has to be installed first). I can't figure out how to create a working desktop shortcut in Windows 10. I can create the shortcut on the Windows 10 desktop OK...

    Lock Screen Timer Shortcut

    ... it just doesn't run when I click on it. I've looked at many websites without any luck.

  • Rich Turner
    Rich Turner almost 6 years
    We recommend you use wsl.exe instead of bash.exe. The former respects your configured default shell, etc. whereas the latter does not.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @RichTurner If I only have one shell (the default) will it matter? That said thanks for the advice and I will use wsl.exe going forward (after I reinstall over the broken 16.04).
  • Rich Turner
    Rich Turner over 5 years
    bash.exe is deprecated and may be removed from future OS releases. Should be reason enough ;)
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @RichTurner Well it gets rid of the awkward "Bash on Windows" too :)
  • Fuhrmanator
    Fuhrmanator about 5 years
    @RichTurner when I try using e.g. C:\Windows\System32\wsl.exe -c ls I get /bin/bash: - : invalid option. It seems wsl.exe doesn't grok -c?