Solved

task scheduler starts .EXE but EXE hangs

Posted on 2014-10-03
8
362 Views
Last Modified: 2014-10-09
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
0
Comment
Question by:Rob Rudloff
  • 4
  • 3
8 Comments
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 150 total points
ID: 40360337
anything that interacts with the desktop must run when a user is logged on.
0
 

Author Comment

by:Rob Rudloff
ID: 40360494
"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
 
LVL 11

Assisted Solution

by:zalazar
zalazar earned 350 total points
ID: 40362679
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
 

Author Comment

by:Rob Rudloff
ID: 40365063
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
Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

 

Author Comment

by:Rob Rudloff
ID: 40370341
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
 
LVL 11

Assisted Solution

by:zalazar
zalazar earned 350 total points
ID: 40365625
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
 

Author Comment

by:Rob Rudloff
ID: 40365709
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
 
LVL 11

Accepted Solution

by:
zalazar earned 350 total points
ID: 40369582
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

Featured Post

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Join & Write a Comment

Know what services you can and cannot, should and should not combine on your server.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

706 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

21 Experts available now in Live!

Get 1:1 Help Now