Script: Check if VNC-Server is frozen

Developers may discuss here.
Post Reply
User avatar
Rhino Cracker
Posts: 4
Joined: 2011-12-01 12:53

Script: Check if VNC-Server is frozen

Post by Rhino Cracker »

Hi all, I'm not sure, whether this is the right subforum for it, but I wanted to share something with you.
I oftenly faced the issue that my VNC-Server is frozen.
So I've written small script using NCat (from NMap) that checks, whether the server is still responding, and restarts it if necessary:


Code: Select all

@echo off

REM newer versions of NCAT can be found here:
REM XP-compatible version is here:
set netcat=R:\Programme\DOS\nmap-6.47\ncat.exe
set outfile="out.txt"
set vncserver="D:\Programme\UltraVNC\winvnc.exe"
del %outfile%

set found=0
FOR /F "delims=" %%A IN ('echo Hello ^| %netcat% -4 -i 1 5900 -o out.txt') DO (
REM for each line
  if "%%A"=="RFB 003.008" (
    set found=1
  echo line: %%A
  echo found: !found!
echo found final: %found%

if %found%==1 (
  echo UltraVNC-Server is responding correctly ==^> do nothing and exit
  goto :end
) else (
  echo UltraVNC-Server doesn't respond ==^> Restart it:
  echo Taskkilling:
  TaskKill /F /IM winvnc.exe
  echo Restarting:
  start "" %vncserver%
  echo %DATE% %TIME% restarted UltraVNC-Server >> UVNC-Restart-Log.txt

echo EXIT
REM win10 only:
timeout /T 600
REM if existing:
REM warten.exe 600000
REM if not:
REM ping -n 600 > NUL
REM this just keeps the cmd window open for a bit so you might find it when connecting.
It's built on the fact, that uvncs will respond with RFB 003.008 to any packet sent to it - as long as it's not frozen, of course. :)
The script is properly running on a XP machine. The testing part can also work with Win10 (or any in between). However, you might have to modify the start "" %vncserver% line (to start for the correct user) and/or give the script admin privileges to kill the running+frozen winvncs.exe.
Post Reply