65.9K
CodeProject is changing. Read more.
Home

Program Executer Timer

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.47/5 (8 votes)

Jan 17, 2006

1 min read

viewsIcon

75989

downloadIcon

490

A program to execute any EXE, then close it after a specified span of time.

Introduction

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.

Background

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: http://MySite.com, 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 
Process.Start(strProgramName,strURL)

' 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
        'end 
        IE1 = IE.GetValue(i)
        IE1.Kill()
    Next
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
    Else
        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.

History

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