Script: Check if VNC-Server is frozen

Developers may discuss here.

Script: Check if VNC-Server is frozen

Postby Rhino Cracker » 2021-02-28 08:49

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:

UltraVNCServerWatchdog.bat
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

REM newer versions of NCAT can be found here: https://nmap.org/download.html
REM XP-compatible version is here: https://nmap.org/dist/nmap-6.47-win32.zip
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 127.0.0.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%
echo.

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
)



:end
echo EXIT
REM win10 only:
timeout /T 600
REM if existing:
REM warten.exe 600000
REM if not:
REM ping 127.0.0.1 -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.
User avatar
Rhino Cracker
 
Posts: 4
Joined: 2011-12-01 12:53

Return to Developer discussions (mainly user-mode)

Who is online

Users browsing this forum: No registered users and 1 guest