Solved

How did trigger off my VB exe file automatically

Posted on 2000-04-07
16
258 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:explorer007
  • 6
  • 3
  • 3
  • +3
16 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 2695696
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2695781
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
 
LVL 2

Expert Comment

by:DawsonB
ID: 2696437
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
 

Author Comment

by:explorer007
ID: 2696500
I would appreciate if you could you be more specific ... DawsonB

KC
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2696568
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
 

Author Comment

by:explorer007
ID: 2696670
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2696723
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
 
LVL 12

Expert Comment

by:mark2150
ID: 2697163
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 14

Expert Comment

by:wsh2
ID: 2697184
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
 
LVL 12

Expert Comment

by:mark2150
ID: 2697196
Done a bit 'o work in VB using timers...

M
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2697240
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
 
LVL 2

Expert Comment

by:DawsonB
ID: 2697671
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
 
LVL 2

Expert Comment

by:DawsonB
ID: 2697673
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
 

Accepted Solution

by:
Arachn1d earned 30 total points
ID: 2698772
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2698848
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
 

Author Comment

by:explorer007
ID: 2701097
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now