Strange behavour of a scheduled vb exe

I have created a VB6 exe to copy some set of files from one network location to the other.  It also worked well when i ran it directly.  But, the problem creeps up when i schedule the exe to run automatically.  I have scheduled it to run at 5 AM in the morning.

When i check that exe every morning, it will be running from morning 5 am to the moment i click on it.  When i click on that window it will get focus and then only it will continue its execution.  Until i click on that app window, it will remain still on the desktop but, will not be executing.

I tried changing the system, tried with different operating systems (xp/2003) and even i have rewritten that application in vb.net too. But, nothing helped!

I still have that problem and i need to click on that application window every morning to make it to continue its execution.

If somebody has faced a similar kind of problem or if anybody has some solution for this issue please reply back to me...
CIPL-SenthilAsked:
Who is Participating?
 
CIPL-SenthilConnect With a Mentor Author Commented:
Hi Guys,
I have identified the problem with the help of my colleagues.  Its about application activation.
When we directly run an application, first the form load even occurs and then followed by the form activate event.  But, when the windows scheduler invokes an application, the application is not getting activated, its just getting started, that's it.
In my case, the problem was I had written the code in form activate event and since my application is getting initiated through windows scheduled task and didn't get activated, it simply didn't continue with the code that i wrote in activate event.
So, I just moved the code to form load event and it worked.
However, my thanks for Altwies for his clue about activation and thanks for vinodsnair2001too for the response.
0
 
vinodsnair2001Commented:
Since a Window application requires users to be logged in in order to excute. Try to create a dos batch program or make this application to a windows service which doesn't need users to be logged in to the machine.
0
 
AltwiesCommented:
Try Creating a Timer that does a DoEvents in the timer thread, or executes the copy!

See if that works!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
CIPL-SenthilAuthor Commented:
Hi vinodsnair2001,
Actually I think it doesn't require a login to run a scheduled windows application.  You can even find this option in task properties dialog of Windows scheduled tasks -- "Run only if logged on". 
However, I've disabled that property too, so that wouldn't make any trouble.  Apart from that, another noticable thing is that another application has also been scheduled for every 2 hours in the same system by my colleague and it runs perfectly every time.  I am also sure that the other application doen't make any impact on my problem because I have already tried scheduling my application in other systems  where there were no other applications scheduled with it.
So, I feel the problem lies somewhere else that I desperately wanting to know.  Any further help on this regard is highly appricated.
Thank you very much for your reply!
0
 
CIPL-SenthilAuthor Commented:
Hi Altwies,  Thanks for the reply...  
Actually I have scheduled my application using Windows scheduled tasks, so I do not have the need to use timer in my application. And that do events stuff too:  what's the point of using do event at the begining of the process itself when an application just gets initiated. The other fact is, I have scheduled two other applications too (Windows applications) that I don't find to be making any problems, they runs exactly at time - no problems.
So, I think its some other problem..  Whatsoever I haven't got it yet and I definitely need you guys help finding the cause.  So, please suggest your solutions..
0
 
AltwiesCommented:
Hi again,

It may be that scheduling the app is not enough especially if windows decides it is not the active application. This is why I suggested a timer that activates a DoEvents() finction. This will guarantee that your app is the active apoplication.

Another thing to try is to call the Win API :
 SetWindowPos(hWnd, HWND_TOPMOST, 0, 0,  0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
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.