Task scheduler help needed

Task scheduler help needed

Anonymous
Not applicable
2,393 Views
6 Replies
Message 1 of 7

Task scheduler help needed

Anonymous
Not applicable

Here's an issue that's really messing with my mind.  If anyone want's to tackle it, I'd be soooo grateful.

 

I have a set of tasks that I have set up to run on my computer after I've left for the day. 

  A .bat file opens an AutoCAD session and then runs a .scr.

  The .scr provides custom commands for a series of extraction and publishing applications.

  The extraction and publishing applications that are run are dlls compiled from vb.net code.

 

1) When I initiate the .bat file manually (double-click) it all runs perfectly.  Really, perfectly.  However,

2) When I set either the Windows task scheduler or a downloaded application called System Scheduler (pretty much the same thing) to initiate the .bat file later at night, each application called by the .scr only partially runs.  For example, with the extraction applications, the code deletes the existing .txt files (previous extraction data) then extracts from a layout and rewrites the .txt file.  Using the schedulers, the previous .txt files are deleted, but then the app closes and it goes to the next one.  The new extractions aren't done.

 

The ONLY difference is how the .bat file is invoked; manually started vs. scheduled as a task.  The actual code is buried behind a .scr within a dll.  The .scr and .dlls are all exactly the same in each method of .bat initiation.

 

So why do the scheduling applications invoking the .bat file cause the dlls to only partially run, while manually invoking the .bat file makes everything run to completion the way it should?  In my tiny mind, the scheduling applications simply initiate the .bat file the same way as my double-clicking it would.  But my tiny mind would apparently be wrong.

 

Do any of you brilliant users have a suggestion or know of a different forum which may be more appropriate?

 

Thank you,

Erik

0 Likes
Accepted solutions (1)
2,394 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

Firstly, I am sure you are aware of running AutoCAD, a heavy resources-hungry desktop app unattended is a risky work (i.e. there are many chances AutoCAD would stop and wait for user interaction, such as dismiss a warning message box). But since you run your BAT file OK for your specific process, you might be fine on this.

 

As for running the same BAT (or any app, for that matter) as Windows' Scheduled task, what user account you configure the task to run with? When you test your AutoCAD process, AutoCAD runs with certain profile associated to your account (thus only available to you when you logs into the computer), which defined a lots of AutoCAD resoources available for AutoCAD. If the scheduled task runs with other user account (system account, or whatever you configured), it would start AutoCAD with different profile (or if that account with the task runs the first time with AutoCAD, it would create a default/unnamed profile, which might be different from the profile you use for your test run. Therefore the AutoCAD started by the task might not be able to work as you expected.

 

I was in similar situation very long time ago, where I need to do some batch processing with AutoCAD. I wrote an stand-alone app that automate AutoCAD for the batch processing; and created an scheduled task that runs with my user account. And then I kept the computer on with my user account logged in, so the task ran OK during the night. Later I simply added a timer to my app, so I can when to run the batch processing. So, I only needed to start my app, set timer, and then lock my computer (still logged in), and left for home.

 

Anyway, for your issue at hand, I would first see/try what account is used to run your task and try use your account.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 7

Anonymous
Not applicable

Thank you for replying.

 

Running the process manually or as a scheduled task is the same:

- Both on my own computer with my own account, logged in.

- Both correctly run the .bat file to start ACAD and initiate the script with the commands

- Both initiate the applications called in the script (custom commands).  

- Everything is the same up to this point.

If I had started by double-clicking the .bat file, every application (dll) in the script runs to completion.

If I had started the process by using a scheduler, everything works the same except each dll stops partway through its work.  

 

There's something different about using the task schedulers vs. manually starting the .bat file by double-clicking, because that's the only difference.  

 

I'm trying to figure out what is it about Windows Task Scheduler and System Scheduler by Splinterware, each of which cause the dlls to terminate prematurely.  

 

Erik

0 Likes
Message 4 of 7

fieldguy
Advisor
Advisor
Accepted solution

Are there any network file paths involved?  If yes, I would try a UNC path - like \\\\server\\folder 1\\folder 2...

If it is a user account issue, drive mapping might not be available or assigned. 

I agree that Task Scheduler is different.  There is an API but creating your own in code is the same as using the interface IMO.  My problems occurred when automating MS Office tasks - software licensing is an issue.  

Task Scheduler API reference >>here<< 

0 Likes
Message 5 of 7

dgorsman
Consultant
Consultant

So here's a question: what happens if you manually prompt the task to run from the Task Scheduler?  What result does it give?

 

Chances are there is a security/permissions problem and you'll have to build some verbose logging tools into your system to see where it actually fails.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 6 of 7

Anonymous
Not applicable

When I manually prompt the tasks from the task scheduler I get the same result as if I allow it to run as a scheduled task; incomplete execution.  

Another suggestion was to use UNC paths rather than drive letters.  The paths I've been using are all drive letters (not in the .NET code, in the .txt files that the app reads paths from).  I'm updating to UNC in the .txt files and will test that shortly.

I really appreciate the responses and suggestions.

Erik

0 Likes
Message 7 of 7

Anonymous
Not applicable

That was the problem.  All of the paths in the .NET code were proper UNC paths.  But the code is written to read lists of paths from .txt files (which are easily updated without recompiling), and all of those paths were letter drives.  I changed all of the paths in the .txt files to UNC and everything works to completion.  

 

My assumption was that since I'm running the application from my own account, it would recognize the letter drives.  But I'm understanding that the task scheduler is not simply starting the .bat file on my machine and letting my machine run from there; it's actually playing some role during execution of the code that the .bat file initiates.  I don't understand how that works, just that it appears to work that way.  

 

At any rate, it seems to be working with the .txt file paths changed to UNC.  I've only tested it by manually initiating the .bat file from task scheduler.  I'll set it up to run as a scheduled task.  I expect it will work, but will believe it when I see it.

 

Thank you for all the replies and suggestions.  

 

Erik