Strange behavour of a scheduled vb exe

Posted on 2009-12-21
Last Modified: 2013-11-10
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 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...
Question by:CIPL-Senthil
    LVL 2

    Expert Comment

    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.
    LVL 1

    Expert Comment

    Try Creating a Timer that does a DoEvents in the timer thread, or executes the copy!

    See if that works!

    Author Comment

    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!

    Author Comment

    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..
    LVL 1

    Expert Comment

    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);

    Accepted Solution

    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.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    A short article about problems I had with the new location API and permissions in Marshmallow
    This is about my first experience with programming Arduino.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now