I've had a few questions on this list, and with the recent help of one of the 
list members, Erik Soderquist, I now have some scripts that work on Windows 
2000, Windows XP, and Linux that do the following on those operating systems:

- Check to see if a client is running RealVNC and, if not, start it, then
- Connect that computer with the now running RealVNC server to a listening 
client anywhere on the Internet
- Stop all RealVNC server activity when done

Background: I have clients around the state, so I can't just drive over and 
fix their systems. B Each client has what I call my Agent program running on 
either Win2k, WinXP, or Linux. B (I'd like to add Win98, since a few people 
interested in working with me still have that, but at this point the deal 
breaker is that my VBS programs don't seem to work well there AND I need the 
"kill" command to work with VNC, and I don't know if it works on Win98.) B 
While my Agent program keeps detailed logs and is rarely the cause of any 
trouble, I still get calls from clients about not being able to use my 
program. B Many times, as anyone who has provided tech support knows, the 
fault is in other problems, such as a new and unconfigured printer, a failing 
hard drive, files deleted without foresight, ID-10T and PEBKAC errors, and 
the like. B While I know my program intimately and can almost immediately 
recognize any problems with it when a client describes the problem, literally 
99% of the time the error is elsewhere, and it can take 45-60 minutes to 
diagnose it over the phone by relaying instructions to the client and waiting 
for a response. B I set up a test with some willing clients by adding 
TightVNC, then changing over to RealVNC. B (I got tech support answers from 
the RealVNC people, but never one on TightVNC.) B I found the average support 
time per call dropped from about 50 minutes to literally about 5 minutes.

As anyone who as done tech support knows, though, the more the end user has to 
do, the longer the call takes. B Each action doesn't add 5 seconds to a call, 
but sometimes a minute. B It takes them time to find RealVNC in the Programs 
menu and then once you tell them to right click on anything, from then on, 
every click, they start asking if it's left or right, and anything they have 
to type needs to be double checked and so on....

Problem: How can I get my clients to run RealVNC as a server, without running 
it as a service so it is always on their systems (thereby making their boss 
wonder if there is a security hole)? B It needs to be easy for them to run 
RealVNC as a server and connect to me as simply as possible. B I can take 
responsibility for closing the server at the end of the call, but I need to 
make sure they can easily kill it if I forget to. B Ideally a one click (a 
double click counts as one click, since it is a single action) solution would 
be the best, or rather, one click to connect, and one click to kill the 
server.

Solution: I created 2 VBS programs that will work on Win2K and WinXP, one to 
connect, and one to kill the RealVNC server. B I also created 2 Linux bash 
scripts (named with .bat for various reasons) that do the same thing. B One 
single action will connect my clients to my listening vncviewer and one 
single action will kill the vncserver on their systems, which disconnects me 
and stops the server to eliminate a possible security concern.

The Scripts: I've commented the scripts. B They are all licensed under the GNU 
organizations (http://gnu.org) GPL. B The names are obvious. B The .bat files 
run on Linux, the .vbs fies run on Windows. B It will be necessary to edit the 
scripts for your setup. B Specifically, you'll need to provide the paths to 
the various RealVNC commands, the IP address of the listening vncviewer or 
its domain (or, if it's dynamic, you can use a service like dyndns.org to 
point to it). B The kill command the Windows scripts uses is not included with 
Windows. B Erik Soderquist was kind enough to provide me with the command and 
allow me to put this link to it: http://www.ravenwind.net/exes/kill.exe here. B 
It can also be found with a good Googling, since it isn't a top secret 
command. B I know WinXP has taskkill, but I found kill worked better overall 
and it was easier to use the same command on both Win2K and WinXP.

An Extra Bonus For Me: One thing I like about this solution is that it allows 
a little extra for my application. B My Agent program I mentioned above has a 
simple control panel. B On one section, B I was able to add a "Connect to Our 
Staff For Help" section with 2 buttons: Connect and Disconnect. B It was easy 
to make the first run the one command to connect via vnc and the second to 
kill all instances of vnc. B I can integrate an instance of RealVNC on the 
clients' computers with my program so they don't have to think at all -- my 
help is only a click away.

I hope this helps a few others out there who are facing similar situations. B 
All I ask is to please let me know if you find the scripts useful. B Include 
"VNC" in the subject line so I can easily spot it. B SpamAssassin gets most of 
my spam, but sometimes misses or gives me false hits.

Thanks to those on this list for their help.

Hal
--------------------------------------------------------------------------------------------
------------Linux Start RealVNC Connection---------------------------------
#!/bin/bash
#-----------------------------------------------------------------------------
#VNCStart.bat
#by Hal Vaughan
[EMAIL PROTECTED]
#Licensed under the GPL (General Public License) of gnu.org
#
#Connect a RealVNC server on this system to a vncviewer listening on the
#Internet.
#
#First we try to connect with the viewer.  If it is successful, we don't need
#to do anything.  If it isn't, then we kill any possible server using the
#display we're using, then start a server, then connect
#
#NOTE: If you don't want to use :1 as the display, feel free to change it
#NOTE: Some debugging statements are left in place but commented out, which
#may make troubleshooting easier.
#-----------------------------------------------------------------------------
#Enter either the address or domainname of the system with a listening
#vncviewer here.  If you have a dynamic IP, I suggest using dyndns.org or a
#similar service and something that will notify it every time your IP address
#changes
dest=mydomain.com
#Replace next line with the path to the directory where the vncserver and
#vncconfig commands are.  Likely there is no need to change
cpath=/usr/bin/
cmdserv=$cpath"vncserver :1"
cmdcnt=$cpath"vncconfig -display :1 -connect $dest"
cmdkill=$cpath"vncserver -kill :1"
#echo "Server: $cmdserv"
#echo "Connect: $cmdcnt"
if $cmdcnt >/dev/null 2>&1; then
#       echo "Worked on first try"
        exit
else
#       echo "First try didn't work"
        $cmdkill >/dev/null 2>&1
        $cmdserv >/dev/null 2>&1
        $cmdcnt >/dev/null 2>&1
#       if $cmdcnt >/dev/null 2>&1; then
#               echo "Worked 2nd time"
#       else
#               echo "Did not work 2nd time -- Please contact tech support"
#       fi
fi
------------Linux Stop RealVNC---------------------------------
#!/bin/bash
#-----------------------------------------------------------------------------
#VNCEnd.bat
#by Hal Vaughan
[EMAIL PROTECTED]
#Licensed under the GPL (General Public License) of gnu.org
#
#Stop all VNC servers on a Linux system
#
#First we use 'ps -ax' to get a task list, then use grep, head, & sed to
#get rid of any entries for grep or vncserver -kill commands.  We take the
#first line, which will be a vncserver task and get the display number, then
#use that to kill the process.  We repeat as often as needed to kill all
#servers.
#NOTE: Some debugging statements are left in place but commented out, which
#may make troubleshooting easier.
#-----------------------------------------------------------------------------
#Replace with your path to the vncserver command
cpath=/usr/bin/
cmdkill=$cpath"vncserver -kill :"
output=`ps -ax 2>/dev/null|grep Xvnc|head -n1|sed -e 
's/^.*grep.*$//;s/^.*kill.*$//'`
while [ -n "$output" ]; do
#       echo "Active server: $output"
        line=${output#*Xvnc}
        line=${output#* :}
        line=${line%% *}
        cmd="$cmdkill$line"
#       echo "Command: $cmd"
        $cmd >/dev/null 2>&1
        output=`ps -ax 2>/dev/null|grep Xvnc|head -n1|sed -e 
's/^.*grep.*$//;s/^.*kill.*$//'`
done
------------Windows Start RealVNC Connection---------------------------------
'-----------------------------------------------------------------------------
'VNCStart.vbs
'by Hal Vaughan
'[EMAIL PROTECTED]
'Licensed under the GPL (General Public License) of gnu.org
'
'Connect, with us as a server, to a listening vncviewere on the net.  Works on
'Winows 2000 and Windows XP systems.
'
'First we try to connect to a listening vncviewer.  We wait 3 seconds, just
'in case and to give the command time to work, then we check the output.  If
'the error output exists and contains the error message we know is telling us
'there is no running vncserver, we kill all vncservers, then run one, then
'connect
'NOTE: Some debugging statements are left in place but commented out, which
'may make troubleshooting easier.
'-----------------------------------------------------------------------------
qm = chr(34)
'Replace mydomain in the line below with your IP address or domain name.  If
'you have a dynamic IP address then I suggest a service like dyndns.org and a
'program that will update them when your IP address changes
sDomain = "mydomain"
'Replace the path below with the path to the kill command on your system.
sCmdKill = qm & "W:\kill.exe" &  qm
sOptKill = "winvnc*"
'WinXP has taskkill, and you can use that instead.  If you do, then comment 
out
'the two previous lines that set up the command for kill and uncomment the 
lines
'below.  My experience was using kill on both 2K/XP was easier and behaved 
better
'than taskkill
'sCmdKill = qm & "taskkill" &  qm
'sOptKill = "\IM winvnc* \F"
'Replace the path below with the path to the RealVNC program on your system.
'Likely this one will work.
sCmd =  qm & "C:\Program Files\RealVNC\VNC4\winvnc4.exe" & qm
sCmdServ = sCmd & " -noconsole"
sCmdCnt = sCmd & " -connect " & sDomain
sCmdKill = sCmdKill & " " & sOptKill
sFlag = "existing VNC Server."
Set WshShl = WScript.CreateObject("WScript.Shell")

'Now that we've got all the strings and objects we need, let's try to connect
'to our viewer.  Once done, wait 3 seconds (for a complete run), then check
'the output.
'WScript.Echo "Connect: " & sCmdCnt

Set oExec = WshShl.exec(sCmdCnt)
iCheck = 1
'oExec.StdIn.Write VbCrLf
WScript.Sleep 3000
sOutput = oExec.StdOut.Read(500)
sError = oExec.StdErr.Read(500)

'WScript.Echo "Output: " & sOutput
'WScript.Echo "Error: " & sError
sIdx = InStr(sError, sFlag)
'WScript.Echo "Index: " & sIdx

'If we found the string in sError, then it didn't work, so we kill any running
'RealVNC server and start our own, then connect.

If sIdx > 0 Then
'       WScript.Echo "Kill: " & sCmdKill
        WshShl.Run sCmdKill, 0, True
'       WScript.Echo "Server: " & sCmdServ
        WshShl.Run sCmdServ, 0, False
        WScript.Sleep 1000
'       WScript.Echo "Connect: " & sCmdCnt
        WshShl.Run sCmdCnt, 0, False
End If
------------Windows Stop RealVNC---------------------------------
'-----------------------------------------------------------------------------
'VNCEnd.vbs
'by Hal Vaughan
'[EMAIL PROTECTED]
'Licensed under the GPL (General Public License) of gnu.org
'
'Stop all VNC servers on a Windows 2000 or Windows XP system
'
'Simple -- use 'kill' command to stop all instances of any program matching
'"winvnc*" wildcard pattern
'NOTE: Some debugging statements are left in place but commented out, which
'may make troubleshooting easier.
'-----------------------------------------------------------------------------
qm = chr(34)
'Replace "W:\kill.exe" with the path to the kill command on your system.  If
'you don't have the kill command, you can find it and download it easily
'enough with a good Google search
sCmd = qm & "W:\kill.exe" &  qm
'WinXP uses taskkill, but I found it didn't work as well, and Kill works on
'BOTH 2K and XP  If you want to use taskkill, delete the above line and
'uncomment the one below
'sCmd = "taskkill"
'The next line is the option to use for the kill command.  If you are using
'taskkill instead, delete (or comment out) this line and use the uncommented
'one after it
sKillOpt = "winvnc*"
'sKillOpt = "/IM WINVNC4* /F"
sCmdKill = sCmd & " " & sKillOpt
Set WshShl = WScript.CreateObject("WScript.Shell")
'WScript.Echo "Command: " & sCmd
WshShl.Run sCmd, 0
_______________________________________________
VNC-List mailing list
[email protected]
To remove yourself from the list visit:
http://www.realvnc.com/mailman/listinfo/vnc-list

Reply via email to