task scheduler starts .EXE but EXE hangs

Hi.
We have a few VB applications that run nightly and are started from Task Scheduler on a server.  Those applications start, they do their thing, then close/end themselves, per code in the EXE itself.
I have a new one that I have set to start exactly like the others, but this one hangs once Task Scheduler starts it.  See ScreenCapTaskMgr1.JPG

In all cases, the Task Scheduler actually calls a .CMD (batch) file, and in the batch file is the command to start the EXE.   Similar to the others, the batch file for the one that does not work looks like this (shortened to 1 line for for testing):
start /d "E:\corpapps\Burns TSYS Batch" BurnsTSYSBatch.EXE 

Open in new window

The Task Scheduler calls the task as in ScreenCapTask2.jpg

All the other tasks are set to "Run whether user is logged on or not" and work fine, and this is the preferred setting.  The new EXE will run properly (not hang) only if this setting is set to "Run only when user is logged on".   See ScreenCapTask1.jpg

I can't blame the batch file -- If I run the batch file directly (double-click it) the EXE starts and closes itself, as it should.

What is different about this EXE is that it includes an ActiveX control that the others don't.   But, I reiterate here that the EXE runs fine on the server if I just double-click it, or double-click the .CMD file that starts it.

The EXE has a log file that it writes to immediately upon starting, and I noticed that when it hangs, it never writes to that file -- so it's not making it far through the code before hanging.

So, perhaps when the EXE is started as "Run whether user is logged on or not", it is actually executing in a "user space" that does not have the ActiveX registered?   I am logged in as Administrator, so you'd think there's not an "authority" issue.

Any suggestions?
ScreenCapTask1.JPG
ScreenCapTask2.JPG
ScreenCapTaskMgr1.JPG
Rob RudloffIT Development SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
anything that interacts with the desktop must run when a user is logged on.
0
Rob RudloffIT Development SpecialistAuthor Commented:
"interacts" in what manner?
I have a test app that simply displays a form, then starts a timer which shuts down the app in 15 seconds.  I set up the same Task Scheduler & .CMD scenario as in my problem above.  Although I don't actually "see" the form displayed, I do see it the process (in Task Manager) start and stop automatically.
0
zalazarCommented:
It might be that the ActiveX control do not require user interaction but does make calls to functions that require the application to be running in user interactive mode.
If this is indeed the case then it might be necessary to look into the code for things which are related to interactive mode (e.g. displaying forms/windows, making calls to (form) controls).
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Rob RudloffIT Development SpecialistAuthor Commented:
OK, I've been removing bits of code until the Task Scheduler successfully runs.  I also made some little test apps.

Actually, applications that display forms are fine --
The form never shows, but calls to open and close a form work fine (but are never actually seen).
Calls to ActiveX controls on unloaded forms work fine (as expected, the forms are loaded upon any reference made to a control on the form)
0
Rob RudloffIT Development SpecialistAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for RobRud's comment #a40365063
Assisted answer: 250 points for David Johnson, CD, MVP's comment #a40360337
Assisted answer: 250 points for zalazar's comment #a40362679

for the following reason:

What fixed my app was removing a call to a function in a DLL.  
   
Wherever Task Scheduler runs programs "whether user is logged on or not" apparently does not have the DLL registered.  The DLL resides in the same folder as the EXE (App.Path).  The mystery is why it runs (with the DLL) outside of Task Scheduler, but not from Task Scheduler.

So, I suspect the DLL was not registered correctly.   This is a 32-bit app running on a 64-bit OS.   I unregistered the troubled DLL, and re-registered 2 ways, just to be safe:

c:\Windows\system32> regsvr32 "E:\corpapps\MyAppPath\Picky.DLL"
c:\Windows\SysWOW64> regsvr32 "E:\corpapps\MyAppPath\Picky.DLL"

One of those fixed the problem (I suspect the second).
0
zalazarCommented:
Very good to hear that you found a solution and thank you very much for the detailed explanation.

When a DLL is registered with "C:\Windows\system32\regsvr32.exe", regsvr32 automatically recognizes if it's a 32-bit DLL and if it's 32-bit DLL it automatically calls the SysWOW64 regsvr32 version which registers it in the SysWOW64 environment but it's not a problem of course if you register it twice.

I understand that you like to close the question since you found the solution yourself.
The comments from David Johnson (and me) were pointing into looking into the code for things related to interactive and it did turn out that it was probably the DLL and not the interactive.
Stil I like to bring to your attention that altough the problem was solved by yourself you should not forget that we as "experts" are spending time on the question and trying to give comments which points into the right direction (like looking into the code).
Anyway, it's fine if you like to close the question and I'm glad it's solved.
0
Rob RudloffIT Development SpecialistAuthor Commented:
OK.  I'm going back and adding back in functions to the application and forms.  
I was considering removing all forms from the app just to get around the "interactive mode" limitation, but since it doesn't seem to be a limitation -- so I've left the forms in.  (The user does not need to do or see anything with the forms for my app to run.)

Can you provide clarity on "the code for things which are related to interactive mode (e.g. displaying forms/windows, making calls to (form) controls)" ?

What things won't run in "interactive" mode, so I know what to avoid?  From my test apps, it looks like the code that displays forms/windows doesn't fail, it just doesn't display to the user.  Same with calls to ActiveX controls on those "unseen" (but loaded) forms (which is now working for me, fortunately).   Do you mean just that ?  -- that if the user (not the code) needs to interact with the form, it must run in interactive mode?

Thanks.
0
zalazarCommented:
Indeed what you describe about user interaction.
Displaying normal forms should be ok but modal forms/dialogs will not work. Reading a control from a modal form will probably also not work.
Within .NET there is a property which prevents displaying any modal dialogs or message boxes.
http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.userinteractive(v=vs.110).aspx
Best of luck.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

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.