Click here to Skip to main content
Click here to Skip to main content

Program Executer Timer

, 17 Jan 2006
Rate this:
Please Sign up or sign in to vote.
A program to execute any EXE, then close it after a specified span of time.


This article describes implementing something like the scheduled tasks for Windows, in a Web application, and this can be used without permissions from the administrator.


I was working on an ASP.NET application and they required me to solve a problem of calling a web page at 12:00 PM everyday to do something.

Using the code

It's very simple. It uses a file placed on c:\named uRL.txt.

This file describes what a program will do, and other details, like:

In this example:

  • NotePad.exe, is the application you want to invoke. It could be "Explorer" or "Internet Explorer" or whatever program you want to open.
  • The second parameter here is the file to open: c:\Mytestfile.txt. It could be a URL like this:, if you want IE to open it for you.
  • 36000 - this is the time interval in seconds, 36000 if you want it to check each hour.
  • 17 - this is the start time specified in a 24 hour clock.
  • 12000 - this is the time to wait to close the program.
' this line to execute the program placed
' on the c:\URL.txt (Notepad.exe) on this example 

' this Function to kill the process
Function Kill()
    Dim IE As System.Diagnostics.Process()
    IE = Process.GetProcessesByName(strProgramName)
    Dim i As Integer
    Dim IE1 As System.Diagnostics.Process
    For i = 0 To IE.Length - 1
        IE1 = IE.GetValue(i)
End Function

' And this function to check if we are
' in time to execute the program ?

Function checker() As Boolean
    Dim currentHour As Integer = DateTime.Now.Hour
    If currentHour >= Integer.Parse(strDailyInterval) _
           And currentHour < Integer.Parse(strDailyInterval) + 1 Then
        checker = True
        checker = False
    End If
End Function

Points of Interest

It can be used in an ASP.NET application, or for remotely controlling PCs on a LAN. Place the URL.txt at any path, then you can load whatever site, or execute any program on the remote PC.


Hope you like it. I will be glad to see your comments in the forum below Smile | :) .


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author


Egypt Egypt
No Biography provided

Comments and Discussions

GeneralUpdated Version: PinmemberTareq_Gamal8-Nov-06 11:13 
QuestionSource Code link broken.... PinmemberTheQuank23-Jun-06 5:47 
AnswerRe: Source Code link broken.... PinmembertareqGamal7-Jul-06 5:43 
Generalsource upload PinmemberTareq_Gamal26-Jan-06 4:59 
GeneralWhy it did not kill process Pinmemberjpazgier25-Jan-06 1:36 
GeneralRe: Why it did not kill process PinmemberTareq_Gamal26-Jan-06 4:43 
GeneralRe: Why it did not kill process Pinmemberjpazgier26-Jan-06 6:11 
GeneralRe: Why it did not kill process PinmembertareqGamal27-Jan-06 13:42 
GeneralRe: Why it did not kill process PinmembertareqGamal27-Jan-06 14:12 
GeneralRe: Why it did not kill process Pinmemberjpazgier28-Jan-06 4:49 
I am sorry I missed some parts of code because I tried to give you a chence to search for it in WIN32 help. Below is updated version I hope it will work fine:
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Integer, ByRef lpExitCode As Integer) As Integer
Const STILL_ACTIVE As Short = &H103S
Dim iProcID as integer
Dim iProcessHandle as integer
Dim eAppStyle As AppWinStyle
'start process and get process ID
iProcID = Shell(cCommandLIne, eAppStyle, True)
'next get process handle based on iProcID
iProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION, False, iProcID)
'to check if process is active you can use
Dim liReturnCode As Integer
GetExitCodeProcess(iProcessHandle, liReturnCode)
if liReturnCode=STILL_ACTIVE then you application is active and you can close it. If is different it is closed and you do not have to close it.
You can check exit Code for error code returned from application so based on this value you can check if it succed or failed succes is in most cases 0 other value error.
You can store handles to started processes in your application and setup a timer to check the state of processes you started and monitor them or close on specific time.
At the end is good to close handle by executing :
Call CloseHandle(iProcessHandle)

GeneralIt starts a process but doesn't kill it Pinmemberjerryoz24-Jan-06 23:44 
GeneralRe: It starts a process but doesn't kill it PinmemberTareq_Gamal26-Jan-06 4:53 
GeneralRe: It starts a process but doesn't kill it PinmembertareqGamal1-Feb-06 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 17 Jan 2006
Article Copyright 2006 by Tareq_Gamal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid