Skip to content

Instantly share code, notes, and snippets.

@tautomer
Forked from ropnop/startTerminator.vbs
Last active October 30, 2019 11:08
Show Gist options
  • Save tautomer/1644ceff1a42cb57f66faba39067c63e to your computer and use it in GitHub Desktop.
Save tautomer/1644ceff1a42cb57f66faba39067c63e to your computer and use it in GitHub Desktop.
VBS Script to Check if vcxsrv.exe Is Running and Launch Terminator through WSL 2
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
Set objShell = Wscript.CreateObject("Wscript.Shell")
If NOT IsProcessRunning("vcxsrv.exe") Then
objShell.Popup "We will launch vcxsrv.exe first!", 1, "VcXSrv is not running", 64
objShell.Exec("C:\Program Files\VcXsrv\vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl")
End If
args = "-c " & """DISPLAY=$(cat /etc/resolv.conf | grep name | cut -d' ' -f2):0 terminator"""
WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0
@tautomer
Copy link
Author

You don't have to launch vcxsrv.exe manually with this script.

A message box will pop up and auto close in 1s if vcxsrv is not running. You can get rid of this by commenting out the objShell.Popup line.

@tautomer
Copy link
Author

Update for WSL 2, but I'm not sure if it's compatible with WSL 1 or not. Gonna test it out tonight.

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