The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    How to have a program automatically restart if it hangs or crashes

    Discussion in 'Windows OS and Software' started by 72hundred, Jun 16, 2009.

  1. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Hi,

    I'm planning on setting up remote access to my laptop via a VNC server.

    But something that's hindering my initial attempts is that when the program hangs or crashes I've no way or restarting it (when not at that location).

    So ideally I'm looking for a program that would close the server maybe every 2hr's and then restart the program so its error/hang/crash free.

    Is this possible? Is there a specific program or a command prompt run?

    Cheers in advance.
     
  2. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Thanks for the tip.

    I created a file autorestart.cmd with notepad and put the following in;

    :start
    C:\Program Files\UltraVNC\winvnc.exe
    sleep 10
    pskill winvnc.exe
    goto start

    but when I open the file it just repeats itself over and over in a cmd window.

    What should be in the file? Cheers for help!
     
  3. jackluo923

    jackluo923 Notebook Virtuoso

    Reputations:
    1,038
    Messages:
    3,071
    Likes Received:
    1
    Trophy Points:
    105
    Maybe you're telling it to restart every 10 seconds
     
  4. davepermen

    davepermen Notebook Nobel Laureate

    Reputations:
    2,972
    Messages:
    7,788
    Likes Received:
    0
    Trophy Points:
    205
    sounds fine except for sleep 10, as it only sleeps for 10 milliseconds? dunno how sleep works, wait..

    ok sleep doesn't even exist in vista :) (did it ever.. :)).

    oh, another idea:

    go into the taskplaner, and create a task you run all 2 hours (should be able to configure it that way).

    and there put in the batch, make it that way:

    pskill winvnc.exe
    winvnc.exe

    and put that file (together with pskill) into the ultravnc folder, where winvnc.exe is.

    that should do the trick. i hope.
     
  5. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    It seems Task Scheduler only works for daily events, not by the hour.... better that nothing I guess. EDIT: Actually it does, its in the advanced options after you've set it up.

    How would I get the .cmd file to work? Is it possible?
     
  6. jackluo923

    jackluo923 Notebook Virtuoso

    Reputations:
    1,038
    Messages:
    3,071
    Likes Received:
    1
    Trophy Points:
    105
    Maybe you should switch to remote desktop protocal. It's much faster/responsive and it's more reliable.

    E.g use live mesh from mesh.com
     
  7. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    OK set up that .bat file to be hit by the scheduler. It just triggered and the program did not restart. (it wasn't open before trigger)
     
  8. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Thanks but I've put a lot of time into getting this idea to work I'd like to try it for a while before moving on to something else.
     
  9. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Right this is the .BAT file at the moment, and its opening the server but it doesn't kill it initially so I'm thinking there's a problem with the pskill command;

    pskill winvnc.exe
    start "" "C:\Program Files\UltraVNC\winvnc.exe"
     
  10. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Working!

    Working at the moment; had to move the .dll file that came with pskill.

    This is the current file;

    pskill "winvnc.exe"
    ping 1.1.1.1 -n 1 -w 10000
    start "" "C:\Program Files\UltraVNC\winvnc.exe"


    (with the delay just so I can see it happening).

    Had to move pskill into System32 folder. But seems to working fine now - thanks all. Rep on the way.
     
  11. jackluo923

    jackluo923 Notebook Virtuoso

    Reputations:
    1,038
    Messages:
    3,071
    Likes Received:
    1
    Trophy Points:
    105
    Beware that if you move something to System32, in rare cases, that the file will be removed if you do not take ownership of the file or a antivirus sees it as a virus.
     
  12. Kocane

    Kocane Notebook Deity

    Reputations:
    395
    Messages:
    1,626
    Likes Received:
    15
    Trophy Points:
    56
    Code:
    @echo off
    cls
    :program
    echo (%date%-%time%) program started.
    start /wait name_here.exe
    echo (%date%-%time%) program crashes, restarting
    goto program

    Sorry if i've misunderstood something..

    but if you put that as a bat into the same dir as the .exe and replace the name_here.exe with the program exe name, then launch it, it will monitor if the exe (process) is running, if not it will restart it instantly)
     
  13. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    Yea, that's probably not a bad way of doing it. But I wanted something to kill the program and restart it encase there was a error in the program but didn't register as a "crash" - if you see what I mean.
     
  14. Kocane

    Kocane Notebook Deity

    Reputations:
    395
    Messages:
    1,626
    Likes Received:
    15
    Trophy Points:
    56
    Oh... yeah okay.. cant help ya there :p
    auto-end and restart sometimes like guys above mentioned is probably the only way
     
  15. ScuderiaConchiglia

    ScuderiaConchiglia NBR Vaio Team Curmudgeon

    Reputations:
    2,674
    Messages:
    6,039
    Likes Received:
    0
    Trophy Points:
    205
    But what happens if it kills the VNC session while you are using it? If the timeout for the batch occurs while you are one line you are dead. Is VNC that unreliable that you need to do this? I use the built in Windows Remote Desktop function every day for years and don't ever have any such "crash" problems.

    Gary
     
  16. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    I've set it up to kill on the hour, so I'll know its coming. Also once I establish the remote desktop I can change the setting to 2/3/4 hours so I won't be interrupted.

    I don't think VNC is unreliable at all, I've not have a crash yet. But if I'm abroad and trying to get back to the laptop and it crashes I've a fairly insurmountable problem.

    EDIT: I probably give Windows Remote Desktop ago after I've all this set-up, maybe as a back-up for this. Or ifs it better the primary route.
     
  17. ScuderiaConchiglia

    ScuderiaConchiglia NBR Vaio Team Curmudgeon

    Reputations:
    2,674
    Messages:
    6,039
    Likes Received:
    0
    Trophy Points:
    205
    Many years ago (1984) I was the sysadmin for an old "bulletin board" system for a local computer users group. The computer was behind locked doors at a university. If it hung, we I had to get one of the university staff to go and restart it. This occurred often enough that we purchased a unit that attached to a phone line and the wall outlet. The computer plugged into the unit. I could then dial the phone number the unit was attached to and turn the power off and back on by using my phone key pad. I believe the unit was from the X10 folks. Not sure if they still exist, but this sort of thing would help you for ANY eventuality, not just that application hang. Actually they DO still exist: http://www.x10.com/products/x10_tr16a.htm

    Gary
     
  18. 72hundred

    72hundred Revolutions-Per-Millennia

    Reputations:
    392
    Messages:
    1,228
    Likes Received:
    0
    Trophy Points:
    55
    That's a really cool bit of retro knowledge! I don't think I'll go down that route tough, wouldn't suit my current set-up. Thanks.
     
  19. Shyster1

    Shyster1 Notebook Nobel Laureate

    Reputations:
    6,926
    Messages:
    8,178
    Likes Received:
    0
    Trophy Points:
    205
    I can vouch for the Remote Desktop feature in Windows as well (albeit not with such longevity and authority as Gary :D). I've never had it crash or go wonky, even when running over a dubious broadband connection from many, many miles away from home.
     
  20. ScuderiaConchiglia

    ScuderiaConchiglia NBR Vaio Team Curmudgeon

    Reputations:
    2,674
    Messages:
    6,039
    Likes Received:
    0
    Trophy Points:
    205
    Grrrrr! Alright you young whipper snapper....

    ...big ol' grin...

    Gary