How did trigger off my VB exe file automatically

Hi

I need to run my VB program .. basically will be an exe file after every half hour. I do not want to run the program all the time. I want my exe file to trigger itself automatically after every half or one hour.

Please advise

KC
explorer007Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Arachn1dConnect With a Mentor Commented:
If you are using Win98 or 2000, it comes with a command scheduler - Go to Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks
You can schedule any programme from there, as well as lots of other things. Windows '95 may also have this if you have installed either a service pack or IE 4/5, I'm not sure which, but I think it is only Win95b - check your accessories group anyway.
0
 
wsh2Commented:
1. Open a New Standard.Exe project.
2. Add a Command Box to the Form (Command1).
3. Add a Timer to the Form (Timer1).
4. Add a Label to the Form (Label1).
5. Copy/Paste the following into the Form code window.
6. Change the m_strCommandLine to whatever you like.
7. Press F5 to run. The timer program will appear automatically minimized on the System traybar below.

<----- Code Begin ----->

 Option Explicit

Private m_strCommandLine As String

Private Sub Command1_Click()
   
   Unload Form1
   Set Form1 = Nothing
   End

End Sub

Private Sub Form_Load()
   
   ' Program to be Executed
   m_strCommandLine = "c:\MyPath\MyProg.exe" <--- CHANGE
   
   
   Form1.Move _
      Screen.Width * 0.25, _
      Screen.Height * 0.25, _
      Screen.Width * 0.5, _
      Screen.Height * 0.5
   Label1.AutoSize = True
   Label1.Move _
      ScaleWidth * 0.1, _
      ScaleHeight * 0.1, _
      ScaleWidth * 0.8, _
      ScaleHeight * 0.8
   Command1.Move _
      ScaleWidth * 0.1, _
      ScaleHeight - (1.5 * Command1.Height), _
      Command1.Width, _
      Command1.Height
   
   Command1.Caption = "Cancel"
   Form1.Caption = m_strCommandLine
   Form1.WindowState = vbMinimized
   Label1.Caption = "This Program will run every 30 minutes." _
      & vbCrLf _
      & vbCrLf _
      & "To Cancel this timer click on Cancel below"
   Timer1.Interval = 3000 ' 3 Seconds
   Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()
   Timer1.Interval = 1800000 ' 30 Minutes
   Call Shell(m_strCommandLine, vbMinimizedFocus)
End Sub
 
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
wsh2: your program will run all the time, so that is something explorer007 does not want to do?

I think, you might investigate some work on checking what other scheduling software can do for you. In all Windows Operating systems you can find one that is build-in.
If you need your program to work, even if nobody is logged on, then you must transform it into a service (or use a service that calls your program)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DawsonBCommented:
Have you tried WinAT or AT ?
type "AT /?"  (without the "'s) from the command line and if your os has it, then you will see the command line argumets necessary.
0
 
explorer007Author Commented:
I would appreciate if you could you be more specific ... DawsonB

KC
0
 
wsh2Commented:
AngelIII:
As I do not know what explorer007 is up to.. I opted to keep everything quite functional AND VISIBLE.. <smile> and a <wink>.
0
 
explorer007Author Commented:
Actually I was wondering if there could be a procedure to trigger of a VB exe file at specfic sessions (say after every 2 hours). I do not want the program to be running all the time.
Is there any software available to do the same or is it possible thru VB

KC
0
 
wsh2Commented:
Explorer007.. albeit whether it is a VB program or another piece of software.. it has to be running in the computer for it to work.. <smile>. The code provided above will launch as many programs as you like on as many timer / timer interval's as you set up. Er pardon me here for a second.. <aaaaaaccccchhhhhooooo.. I must be getting a virus cold here>.. back to the point.. what are you trying to do? BTW, System Task bar space is cheap.. <wink>.
0
 
mark2150Commented:
wsh2,

Obviously you haven't actually *tested* this code or you'ld know that:

Timer1.Interval = 1800000 ' 30 Minutes

Simply can't work as the Interval is an unsigned 16 bit integer...

You want time intervals over 65000 or so (a little more than a minute) then you need a little static var in the timer service routine to count minutes as they tick over.

Timer.Interval = 60000


Static Mins as Integer
Const Delay as Integer = 30

Mins = (Mins + 1) mod delay
if Mins = 0 then
   ... trigger processing ...
endif

M



0
 
wsh2Commented:
Mark2150:
Hmmmm.. do you mean that because of my "Timer" I am NOT as old as I really am?.. <LOL>.. Good catch Mark2150.. <smile>. Every once in a while one slips through.. <wink>.
0
 
mark2150Commented:
Done a bit 'o work in VB using timers...

M
0
 
wsh2Commented:
Mark2150:
Done a bit 'o work in VB, slapping my forehead and saying Oh My Gawd.  Chit happens.. <smile>.. But at least I am not bald from doing it.. LOL and a <wink>.
0
 
DawsonBCommented:
I used AT (It comes with NT I think) to have a VB program I have written run at 03:30am every day.
The followin is copied from typing AT /? at the command prompt.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.

so, an at command might be

AT 05:30am /every Monday,Wednesday,Friday notepad.exe "MyScirpt.vbs"

should open MyScirpt.vbs in notepad at 04:30am every Monday,Wednesday, and friday. It can also be used to trigger multiple times per day, but not having done this myself, you would need to experiment with the command line argumets to work it out.
Alternatively, there is a 32bit version called WinAT, which I think is just a visual front end for AT, but is much easier to use, just type WINAT from the command line and if you have it, it's easy to work out.
I mus add that I said above that I used(past tense) at, it didn't do what I needed, because I was loading a program wich uses OLE to connect to an already running active x exe and at runs as a different user, therefore couldn't connect to the same instance that was already running. In the end we have bought a program (I think it is about £35, don't know in $) called Macro Scheduler, look at http://www.mjtnet.com/ where you can download a trial version, this is working for what we need.
Good luck
0
 
DawsonBCommented:
Oh, should have added that AT and Macro scheduler run as Services in NT and sit in the background with much lower processing overheads than a "Timer programme"

:-}
0
 
wsh2Commented:
With Windows 95.. the System Agent (Task scheduler) was part of Microsoft Plus!.. an addon you had to purchase.. <sigh>. With Win98 and Win2000 it became a standard feature.. <smile>.
0
 
explorer007Author Commented:
Thanx ... I guess it was a simple answer.. I did think of it earlier .. but full marks to you.
I beleive there was one scheduler which came along with MS Office ... no longer available now.

Cheers mate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.