Skip to content

Instantly share code, notes, and snippets.

@Kvieta1990
Created December 5, 2021 20:28
Show Gist options
  • Save Kvieta1990/e978a58f6ad584c55b6b4bbe0d506d20 to your computer and use it in GitHub Desktop.
Save Kvieta1990/e978a58f6ad584c55b6b4bbe0d506d20 to your computer and use it in GitHub Desktop.
Windows shortcut for WSL Ubuntu apps
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "E:\wsl_ubuntu_app"
shell.Run "cmd /c wsl-app-sudo-runner.bat gedit", 0, false
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "E:\wsl_ubuntu_app"
shell.Run "cmd /c wsl-app-runner.bat google-chrome-stable", 0, false
@echo off
for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "vEthernet (WSL)" ^| findstr /C:"IP Address"') do set ip==%%I
set ipAddress=%ip:~1%
powershell.exe wsl "DISPLAY='%ipAddress%':0.0" %1
@echo off
for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "vEthernet (WSL)" ^| findstr /C:"IP Address"') do set ip==%%I
set ipAddress=%ip:~1%
powershell.exe wsl "DISPLAY='%ipAddress%':0.0" sudo %1
@Kvieta1990
Copy link
Author

Kvieta1990 commented Dec 5, 2021

  1. With the setup in gist file, we don't have to put the VBScript and .bat files in the same directory, since the path to .bat file to be executed in VBScript file is specified explicitly with full path.

  2. It is the VBScript files that are to be executed to launch the WSL Ubuntu Apps from Windows. So, we may need to further create shortcuts for those VBScript files. After creating shortcuts, we may find it is impossible to directly add those shortcuts to start menu. In this case, we may need to copy those shortcuts manually into Windows start menu -- we can create a folder (which can be with arbitrary name, e.g., Ubuntu Apps) under the following folder and put those shortcuts in it,

    C:\Users\USER_NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Ubuntu Apps

  3. A separate .bat file is also included here to execute some app with sudo privilege. Particularly for gedit, running without sudo privilege for some reason cannot access settings to the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment