Link to home
Start Free TrialLog in
Avatar of explorer007
explorer007

asked on

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
Avatar of wsh2
wsh2

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
 
Avatar of Guy Hengel [angelIII / a3]
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)
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.
Avatar of explorer007

ASKER

I would appreciate if you could you be more specific ... DawsonB

KC
AngelIII:
As I do not know what explorer007 is up to.. I opted to keep everything quite functional AND VISIBLE.. <smile> and a <wink>.
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
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>.
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



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>.
Done a bit 'o work in VB using timers...

M
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>.
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
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"

:-}
ASKER CERTIFIED SOLUTION
Avatar of Arachn1d
Arachn1d

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>.
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