Skip to content

Instantly share code, notes, and snippets.

@avinoamsn
Last active July 3, 2022 16:31
Show Gist options
  • Save avinoamsn/495db3729d6b24ec065a710250657c16 to your computer and use it in GitHub Desktop.
Save avinoamsn/495db3729d6b24ec065a710250657c16 to your computer and use it in GitHub Desktop.
VBScript for quietly launching a Terminator window in WSL with VcXsrv. Code comments link to the guides I referenced while writing the script.
' NOTE: additional discussion & implementations can be found here: https://gist.github.com/ropnop/10800fb5066bd5144d9aaad55a8a4d18
' https://medium.com/@bhupathy/install-terminator-on-windows-with-wsl-2826591d2156
set shell = WScript.CreateObject("Shell.Application")
if not IsProcessRunning("vcxsrv.exe") then
shell.shellExecute "vcxsrv.exe", ":0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto", "C:\Program Files\VcXsrv\", "", 0
end if
shell.ShellExecute "bash", "-c -l ""DISPLAY=:0 terminator""", "", "open", 0
' https://stackoverflow.com/questions/19794726/vb-script-how-to-tell-if-a-program-is-already-running
Function IsProcessRunning( strProcess )
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://."
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
Exit Function
End If
Next
End Function
@Ig0r-M-magic42
Copy link

Thanks dude, it's awesome

@avinoamsn
Copy link
Author

definitely, glad it's useful!

@JulianNicholls
Copy link

Good work, fella!

That was exactly what I needed.

@tomm1996
Copy link

tomm1996 commented Jul 20, 2020

If you want to run for example zsh instead of bash, you can change line 7 to that:
shell.ShellExecute "wsl.exe", "zsh -c -l ""DISPLAY=:0 terminator""", "", "open", 0

@zoloholic
Copy link

zoloholic commented Dec 19, 2020

For WSL2 - Uses nameserver IP address for DISPLAY

I have edited your script, so if the WSL2 nameserver IP changes, It will acquire the new IP in order to execute and open terminator

' https://medium.com/@bhupathy/install-terminator-on-windows-with-wsl-2826591d2156
set shell = WScript.CreateObject("Shell.Application")

if not IsProcessRunning("vcxsrv.exe") then
	shell.shellExecute "vcxsrv.exe", ":0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto", "C:\Program Files\VcXsrv\", "", 0
end if
' terminator.vbs
myCd = "~"
If WScript.Arguments.Length > 0 Then
    myCd = "'$(wslpath -u '" & WScript.Arguments(0) & "')'"
End If
args = "bash" & " -c ""cd " & myCd & "; DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 terminator"""
WScript.CreateObject("Shell.Application").ShellExecute "C:\Windows\System32\wsl.exe", args, "", "open", 0

' https://stackoverflow.com/questions/19794726/vb-script-how-to-tell-if-a-program-is-already-running
Function IsProcessRunning( strProcess )
	Dim Process, strObject
	IsProcessRunning = False
	strObject = "winmgmts://."
	For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
	If UCase( Process.name ) = UCase( strProcess ) Then
		IsProcessRunning = True
		Exit Function
	End If
	Next
End Function

@avinoamsn
Copy link
Author

avinoamsn commented Nov 2, 2021

@zoloholic thanks for the contribution, you should also share your version on this topic's main thread over here.

Edit: nevermind, I see you already did this 😅. You may want to try reformatting with the three-tilde, however, like I did on your above post (I don't have control over the main thread, so you'd have to edit it there).

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