Skip to content

Instantly share code, notes, and snippets.

@ropnop
Created September 29, 2017 00:02
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ropnop/10800fb5066bd5144d9aaad55a8a4d18 to your computer and use it in GitHub Desktop.
Save ropnop/10800fb5066bd5144d9aaad55a8a4d18 to your computer and use it in GitHub Desktop.
VBS Script to Launch Terminator through WSL
args = "-c" & " -l " & """DISPLAY=:0 terminator"""
WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0
@avinoamsn
Copy link

@chazakki Are you asking about starting subl from within WSL using a similar script? You'll probably only need to change the call to WScript.CreateObject(...)..., but I couldn't say what the exact solution is. I bet that there are other examples out there that are closer to what you're looking for.

Additionally, I haven't used subl in years but VSCode runs natively in WSL using a proprietary VSCode server solution. subl may offer something similar, but I haven't looked into this myself.

@r0mdau
Copy link

r0mdau commented Jan 28, 2022

Automatically retrieve the ip address related to your WSL2 adapter using adapter name in the function GetIpFromAdapter, in VBS :

' https://gist.github.com/ropnop/10800fb5066bd5144d9aaad55a8a4d18
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
        WScript.Sleep 2000
end if

StrIP=GetIpFromAdapter("Hyper-V Virtual Ethernet Adapter #2")
shell.ShellExecute "bash", "-c -l ""DISPLAY="&StrIP &":0 terminator""", "", "open", 0

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

Function GetIpFromAdapter( adapterName )
	dim NIC1, Nic
	Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")	
	For Each Nic in NIC1	
	    if Nic.IPEnabled And Nic.Description=adapterName then
	        GetIpFromAdapter = Nic.IPAddress(0)
	    End if
	Next
End Function

@Kahuna26
Copy link

Kahuna26 commented Feb 4, 2022

i used this script since last year. (Many thanks!) After i upgraded my windows to 11 it stopped working and i cant seem to find the problem.
Do you have any experience with terminator wsl2 and windows 11?

@pastephens
Copy link

Giant PITA!

@fahri314
Copy link

fahri314 commented Dec 9, 2023

i used this script since last year. (Many thanks!) After i upgraded my windows to 11 it stopped working and i cant seem to find the problem. Do you have any experience with terminator wsl2 and windows 11?

Windows 11 does not need this script. When you install a program in wsl, you can find windows start menu with its name and you'll see with icon if exist

@fahri314
Copy link

fahri314 commented Dec 9, 2023

I added home directory changes and more reliable IP calculation:

' https://gist.github.com/ropnop/10800fb5066bd5144d9aaad55a8a4d18
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
        WScript.Sleep 2000
end if

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"""
shell.ShellExecute "C:\Windows\System32\wsl.exe", args, "", "open", 0

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

@kamermans
Copy link

Thanks @fahri314

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