Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I schedule a VB app ? 1

Status
Not open for further replies.

patrickdrd

Programmer
Nov 21, 2003
149
GR
Good Morning guys!

I have the following problem: I wrote a VB module, compiled it as an exe, wanted it to run on a schedule
(daily, every one hour), tried doing so by adding it to the task scheduler, but it didn't work!

When I selected run from my task's right click options, the message I got was "Could not start"!

After surfing on the net for this issue, I saw that maybe I had to do it with a timer,
i.e. my app would be running all the time, and the timer could make it run every hour.

However, I'm not so much familiar with timers (if that's the proper solution). Could someone give
me a hint on this?

Thanks in advance guys!
 
Shouldn't it be an activex exe ???

You could also use the NTService control ...

Code for Form load:
=================
If Command = "-install" Then
' Enable interaction with desktop.
NTService1.Interactive = True

If NTService1.Install Then
MsgBox "installed successfully"
Else
MsgBox "failed to install"
End If
End
ElseIf Command = "-uninstall" Then
If NTService1.Uninstall Then
MsgBox "uninstalled successfully"
Else
MsgBox "failed to uninstall"
End If
End
ElseIf Command = "-debug" Then
NTService1.Debug = True

ElseIf Command <> "" Then
MsgBox "Invalid command option"
End
End If

''' ' Connect service to Windows NT services controller.
NTService1.StartService

Private Sub NTService1_Start(Success As Boolean)
Success = True
End Sub

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
When I selected run from my task's right click options, the message I got was "Could not start"!
[\quote]

Does it run when you double click the built exe?



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Yes mattKnight, it does run when I double click the built exe

tb, I'm not sure I understood what you've said. I've never
written an activex exe. How do I handle this?
I just copy and paste my code in a new activex exe?
And then, how will I be able to make a schedule on it?
 
(I can't tell what the main purpose of your program is, but I don't need to know. I'll refer to it as "Task X".)

If you want to use a Timer control with some "quick and dirty"/simplistic/untested code...

1) Put a Timer control on a form that will be loaded all the time your program is running (whether or not the form is visible). Give the control a Name that starts with tmr, like tmrCatnap. Set its Enabled property to True and its Interval property to 64000 (=1 minute; that's almost as large as you can set it).

2) The event handler for the timer's Timer (in this case, named tmrCatnap_Timer) will be executed at that 1-minute interval. In the event handler, include a Static counter to keep track of how many minutes have elapsed since the last time your program executed Task X. (Yes, this could be a module-scope variable instead of a static local variable, but there's no significant advantage to that; no other procedure needs to access the variable.) Conditionally execute Task X and reset the counter.

Code:
Sub tmrCatnap_Timer...
    Static sintCatnaps As Integer
    sintCatnaps = sintCatnaps + 1
    If sintCatnaps >= 60 Then
        ' execute Task X, and then...
        sintCatnaps = 0
    End If
 
I tried it 3 ways and all worked.

Standard EXE with a blank form:
Code:
Option Explicit

Private Sub Form_Load()
    Dim intF As Integer

    intF = FreeFile(0)
    Open "Sched.log" For Append As #intF
    Print #intF, CStr(Now)
    Close #intF
    Unload Me
End Sub

Standard EXE with a single module:
Code:
Option Explicit

Sub Main()
    Dim intF As Integer

    intF = FreeFile(0)
    Open "Sched.log" For Append As #intF
    Print #intF, CStr(Now)
    Close #intF
End Sub

The latter was tested both with and without "Unattended execution" turned on in the Project Properties.

All 3 versions seem to work fine in Task Scheduler. I'd tend to avoid the form and attended versions though, as they might hang if the console is not logged on when the scheduled time hits.

Windows Task Scheduler doesn't have anything to do with ActiveX, NT Services, or Timer controls. Those sound like odd ways to achieve something similar without using Task Scheduler... and why work so hard?


Your scheduling attempt could be failing for a number of reasons. A common one for hobbyists is:

Task Scheduler Does Not Run Tasks When "Run As" User Account Has No Password

Another is due to malformed command lines:

http://support.microsoft.com:80/support/kb/articles/q178/6/91.asp&NoWebContent=1]Scheduled Program Does Not Start in Task Scheduler[/url]

See also:

HOW TO: Troubleshoot Scheduled Tasks in Windows XP
 
Hey

Have you tried it with adding your username and password. i had he same problem,doh


Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top