Link to home
Start Free TrialLog in
Avatar of DavidCulbertson
DavidCulbertsonFlag for United States of America

asked on

Problem running a batch file as a scheduled task

This problem occurs on Windows Server 2008 x64 and Windows 7 x64.  I am running a batch file (.cmd) that starts 60 copies of an application that was written in Delphi 2010.  If I logon to windows and run this batch file it works perfectly.  If I run the batch file as a scheduled task, only 50 instances of the program get started.  The windows system log has 10 entries that read:

Application popup: Hcptransmit: HCPTransmit.exe - Application Error: The exception unknown software exception (0x0eedfade) occurred in the application at location 0x7683b727.

The scheduled task is setup to run with highest privileges and Run whether user is logged on or not.

Any ideas?
Avatar of cjrmail2k
cjrmail2k
Flag of United Kingdom of Great Britain and Northern Ireland image

are you running it as the same user? Also if you log on to (and lock) the server and let the task run, does it fail?
Avatar of DavidCulbertson

ASKER

No, I am running as a different user.  I need to be able to run this as a user that doesn't logon interactively.
the first thig I would try is to change the task to run as the user you are logging on as, this will prove if its a permission issue
I've logged on as the user that is running the task, and run the task.  It works perfectly.
Avatar of Emmanuel PASQUIER
are the tasks long to execute ?
60 app running at the same time would be as long as only 10 tasks at the same time (if you don't have more than 10 cores on the computer)
so you could just create an application that will control the launch of those tasks with a maximum limit running simultaneously. When one finishes, you start the next on the list until done.

then your batch calls that application only
If you can wait monday, I can do that app for you
The app's stay running for a couple hours, periodically checking a database and communicating changes to a remote location.  Each copy communicates to a different remote location.  It's easier for us to write a single threaded application and run 60 copies, than write a multi-threaded application.  I control the start of the app with a batch file that delays between the start of each application.  CPU utilization isn't the issue.
>delays between the start of each application
Maybe the 'time' has passed to start the scheduled task.
The batch file reads:

start hcptransmit.exe
sleep 1
start hcptransmit.exe
sleep 1
.
.
.

The sleep program pauses 1 second.  It's the batch file that is scheduled to run, and it has not finished running, so I don't think that is the problem.  I have tried increasing the delay between each start with no luck.  

It looks to me like there is some limit in the OS for number of processes under a given scheduled task.
ignore that last comment.

trap the exception with a try ..except and get a clue to the error.
change from 100 to 200 the following keys

HKey_LocalMachine\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Configuration

    TaskInMemoryQueue
and
    TaskPerHighestPrivEngine
Changed the registry, but no luck.  Application crashes upon start once about 50 are running.  If I run the batch file from a logged on session, every instance starts.
Hard to tell, but most likely an issue with the desktop heap size for non-interactive sessions. For Windows 7 x64, the interactive heap size is set to 20MB, but for non-interactive its set to 768K. This heap is used for GDI/USER objects, and most likely your app uses a fair share of both. Add in the fact your trying to start 60 instances, and your problem might be there.

To test this:
1 . In Registry Editor, locate the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
2. In the right pane of Registry Editor, click Windows.
3. On the Edit menu, click Modify.
4. In the Edit String dialog box, locate the SharedSection parameter string in the Value data box, and then specify a larger value for the SharedSection parameter. The SharedSection parameter specifies the system and desktop by using the following format, where <xxxx> defines the maximum size of the system-wide heap (in kilobytes), <yyyy> defines the size of the per desktop heap, and <zzzz> is the size of the desktop heap for each desktop that is associated with a non-interactive Windows station:
SharedSection=<xxxx>,<yyyy>,<zzzz>

Example from my x64 Win 7 system (notice the setting of 768):
%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

5. Click OK.
6. Not sure if its required, but restart the system to test.

I would suggest a setting of 1024 to see if this changes the count of instances that are able to start. eg.
... SharedSection=1024,20480,1024 ...

If no difference, then reset the number back. If this allows more (but not all 60) instances to be created, then bump it by another 256K. If this allows all 60 to be started, then your should be good to go.

---

hth,
Russell

maybe there is a (50) connection limit in your database.
a tool for monitoring 60 databases ? and reporting to different locations
easier to write single threaded ?

what if you check all the databases the same way and store the report locally
and then distribute the report to the different location

sample:
App 1: Check database A, report to loc X
App 2: Check database A, report to loc Y
App 3: Check database A, report to loc Z

> better:
App 1: Check database A, report to loc X, Y and Z

less apps and less monitoring queries on database A ...
ASKER CERTIFIED SOLUTION
Avatar of DavidCulbertson
DavidCulbertson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Run two sets of 30; 15 minutes apart. :)
That works.
Based on the latest author comment, the proper solution seems to be comment http://#34144708
i'd really consider a multithreading way
a lot easier to see if that's running than to count all the 60 processes running
@DavidCulbertson

In your original question text, you asked
>>Any ideas?

The http:#34144708 comment solved your problem, which you acknowledged in your http:#34159371 comment.  You did not ask a "why is this happening" question.  As such, your self-closing comment is not correct.
Please read ID: http:#34140406 .  I was testing this solution and ID: http:#34144708 just re stated my idea.  When I stated "it works" I was referring to ID: http:#34144708 .
Thanks for that clarification.  In that case, I withdraw my objection.
My idea of splitting the job into two seperate jobs works.  I would have liked to find out why it doesn't work as one job, but this solution is working.