Running VNC over SSH on Windows

Its been a long time coming but, in keeping with my other write ups on how to run VNC over SSH on Solaris and OS X, I've finally figured out a somewhat reasonable method on Windows.

I had been using STunnel when on Windows, but that has a few draw backs, mainly that it is a less dynamic option because you have to edit a configuration file to set up new tunnels. It can't be done on the fly very easily. Plus, then there is the maintenance of the config file.

So I worked out a method similar to on Solaris and OS X with SSH Port forwarding. Only in this case, using the plink.exe utility that comes with PuTTY. First, the script. For someone who actually knows VBScript and Windows Script Host, this is probably pretty trivial, but for me, one who's tried to stay clear of Windows development, it took a bit of hacking:

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

user = "mock"

result = InputBox("VNC Server to Connect to:", "VNC Server", "")

index = Instr(result, ":")

If index > 0 Then
	host = Left(result, index - 1)
	port = Right(result, Len(result) - index)

	vport1 = CStr(5900 + port)
	vport2 = CStr(5800 + port)

	cmd = "plink " + host + " -batch -l " + user + " -L " + vport1 + ":localhost:" + vport1 + " -L " + vport2 + ":localhost:" + vport2 + " sleep 15"

	WshShell.Run cmd, 0, false

	WScript.Sleep 2000

	WshShell.Exec("C:\\Program Files\\TightVNC\\vncviewer.exe localhost:" + port)
End If

Make sure to save the file with a .vbs extension. I call mine vncv.vbs.

Also, the script assumes the use of TightVNC. It'll probably work with other clients, but you'd have to give that a try.

So, how do you use it. As with the method on the other Operating Systems, SSH Public Key Authentication is used. On Windows, with PuTTY, this means firing up pagent.exe and loading your keys into the agent. I'll leave specifics to the reader, I think I've mentioned it in other entries though.

After that, simply double click on the script, and a prompt will show up asking for the host:port of the VNC server to connect to. Give it a couple of seconds to make the necessary connections and boom, you should be presented with a dialog to enter the password of the VNC server.

If anyone finds this interesting, and would like to add some enhancements, one thing I would like to have is a connection history. So I don't have to type as much.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

mock

Search

Top Tags
Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
Blogroll

No bookmarks in folder