I have WSL bash running in a cmd. I don't use it for anything, it just hangs there to keep the WSL system alive.
When I start X applications:
bash -c "DISPLAY=:0 xmessage hello &"
I get this result:
I can close down the command window without any problems, but it's rather annoying.
How can run commands without getting this cmd window every time?

Here's a simpler solution, which, however, requires a WSH-based helper script,
runHidden.vbs(see bottom section):To apply @davv's own launch-in-background technique to avoid creating a new
bashinstance every time:One-time action (e.g., at boot time): launch a hidden, stay-open
bashwindow. This spawns 2bashprocesses: the Windowsbash.exeprocess that owns the console window, and the WSLbashprocess (owned by the WSLinitsingleton), which is then available for servicing background commands.For every X Window-launching command: Terminate each command with
&to have it be run by the hidden WSLbashinstance asynchronously, without keeping the invokingbashinstance alive:runHidden.vbssource code:Even when launched from a GUI app (such as via the
Rundialog invoked with Win+R), this will not show a console window.If your system is configured to execute
.vbsscripts withwscript.exeby default (wscript //h:wscript /s, which, I think, is the default configuration), you can invokerunHidden.vbsdirectly, and if you put it in your%PATH%, by filename (root) only:runHidden ....Note that use of the script is not limited to console applications: even GUI applications can be run hidden with it.