Solved

task scheduler starts .EXE but EXE hangs

Posted on 2014-10-03
8
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 81

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 12

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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

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
 

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 12

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 12

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

752 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