VB6 app not executing as scheduled task unless user is logged on
I would greatly appreciate some help on this one! It may be a tricky one. :)
Problem
- I have an VB6 application which is set up as scheduled task. It starts every time, but when executing
CreateObject()
it fails if a user is not logged on to computer. - I am looking for information on what could cause this. My primary suspicion is that some Windows API fails.
Key points
- Behaviour confirmed on Windows 2000, 2003, 2008 and Vista.
- The application executes as user X at scheduled time, executed by Windows Task Scheduler.
- It executes every time. Application does start!
- If user X is logged on via RDP it runs perfectly. (Note that user doesn't need to be connected, only logged on)
- If user X is not logged on to computer the application fails.
Failure point
- Application fails when using
CreateObject()
to instantiate a DCOM object which is also part of the application. - The DCOM objects declare .dll-references at startup (globally/on top of .bas-file) and run a small startup function. Failure must be during startup, possibly in one of the .dll-declarations.
Thoughts
After some Googling my initial suspicion was directed at MAPI. From what I could see MAPI required user to be logged on. The application has MAPI references. But even with all MAPI references removed it still does not work.
What is the difference if an user is logged on? Registry mapping? Environment? Explorer.exe is running.
Isn't the user logged on when application executes as the user?
What info would help?
- A definitive answer would be truly great.
- Any information regarding any VB6 feature/Windows API that could act differently depending on whether user is logged on or not would definitively help.
- Similar experien开发者_如何转开发ces may lead me in the right direction.
- Tips on debugging this.
The VB application possibly needs to get hold on to running services that are only running when a user is logged on.
What is the "Identity" setting of the DCOM component.
C:\WINDOWS\system32\Com\comexp.msc
- C:\WINDOWS\system32\Com\comexp.msc
- Component Services
- My Computer
- DCOM Config
- The DCOM Object, right click properties
- Identity tab
Set it to "This User" and set a user with the required permissions, and then run the app as your self to see if the DCOM component can still work, then try again from the scheduler.
We never found out what caused this.
Instead I made a RDP client which I put in Scheduled Tasks. It logged on a user which had the required app in startup. After some time the RDP client forcefully logged out the user (to prevent runaway apps hanging the system).
Not the perfect solution, but a solution nevertheless.
has your VB6 forms?
because when you run scheduled, it run "as a service", so it can't have forms, or if it have forms an enviroment where to show them.
I don't remember what I have used, but exists generic "run as a service" converter exe to run windowed VB6 projects.
Also perhaps you can easy convert your code to run as a VBScript, and schedule it.
精彩评论