I have an executable which I've scheduled to run once in every five minutes (using Window's built-in Task Scheduler). It's crucial that this executable is run because it updates few time critical files. But how can I react if the virtual server running the executable goes down? At no point there shouldn't be more than 15 minutes break between the runs.

As I'm using Windows Server and its Task Scheduler, I wonder is it possible to create some kind of a cluster which automatically handles the situation? The problem is that the server in question is running on Windows Azure and I don't think I can create actual clusters using the virtual machines.

If the problem can be solved using a 3rd party tool, that's OK too. To generalize the question a little bit: How to make sure that an executable is run once in every 5 minutes, even if there might be server failures?


If you can't cluster but you can have multiple machines on the same network then you could wrap your executable in a bit of powershell.

On the first server when you execute it you create a file to indicate success. The second server then runs separate code to look for that temp file, if it doesn't exist it will launch.

Server 1

$strDateTime = Get-Date -Format ddMMyy-hh:mm
$strPathtoTempFile = "D:\TempFile"
$strPathtoEXE = "D:\BIN\file.exe"

IF((Test-Path $strPathtoTempFile) -eq 'True'){remove-item $PathtoTempFile}

Start-Process $strPathtoEXE -Wait
If($Lastexitcode -eq 0){$strDateTime | Out-File $strPathtoTempFile}

Save this as a .PS1 file on server 1 and point your scheduled task to "C:\windows\system32\windowspowershell\v1.0\powershell.exe D:\BIN\script.ps1".

Important to test that your executable returns something to $Lastexitcode if it works. Other wise it will never write the output file. The point of this is that it will catch any failures even if the server is available but the executable fails to execute properly. If this doesn't work try '$?' in the place of $Lastexitcode. This will return True or False. Again you will need to test it.

On Server 2 run this as a scheduled task, but run it every five minutes starting at 1 minute pas the schedule on the first server:

Server 2

$strDateTime = Get-Date -Format ddMMyy-hh:mm
$strPathtoTempFile = "\\Server1\TempFile"
$strPathtoEXE = "D:\BIN\file.exe"

IF((Test-Path $strPathtoTempFile) -eq 'Flase')
    Start-Process $strPathtoEXE
    Send-Mailmessage -smtpserver smtp.server.com -to support@company.com -from executable@company.com -subject "Launched on backup" -body "Executable failed on server1, ran from backup server on $strDateTime"

This should give you a little of the redundancy that you need.

*I haven't tested this but it should get you close

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.