How to Run Gambas and Gambas Apps on Windows using WSL

Prerequisites

You have to have a basic setup consisting of the following in order for this to work.
  • Windows 10 with WSL2 installed
    • For x64 systems: Version 1903 or higher, with Build 18362 or higher.

    • For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.

    • Builds lower than 18362 do not support WSL 2. Use the Windows Update Assistant to update your version of Windows

  • Ubuntu Linux installed in the WSL

There is a simplified install procedure for those who do not have the WSL and Ubuntu systems installed. You can try it out by opening a Powershell account and running wsl --install -d Ubuntu. This seems to be limited to those who are part of the insider program however.
  • An XServer client running on Windows. For example, XMin or VcXsrv.

Running GUI apps under Windows is supported since Windows 10 Build 19044+ or Windows 11.
  • Gambas must be installed

Use these instructions to install Gambas on the Ubuntu version of Linux installed in the WSL

Running Gambas

Set up a desktop shortcut that uses the following command-line string: C:\Windows\System32\wsl.exe DISPLAY=:0 LANG=en_EN.UTF-8 gambas3

Running Gambas apps

Set up a desktop shortcut that uses the following command-line string: C:\Windows\System32\wsl.exe DISPLAY=:0 LANG=en_EN.UTF-8 myprogramm.gambas

Check for Windows

In your Gambas app, you can check to see whether you are running in windows or not, and use that to decide how you are going to do things. Use this snippet of code:
Dim kernel As String
Dim isWindows As Boolean
Shell "uname -a" To kernel
If InStr(kernel, "Microsoft") Then isWindows = True

Acknowledgements

Thank you to Dmitry Bachilo for his information which led to this Howto, and to Christof Thalhofer for mentioning it.

-- John Dovey