zachvaldez
asked on
Schedule a windows bat program to execute
I'd like to schedule to run a windows batch file to execute at a certain time.
What are the steps?
What are the steps?
Go into task scheduler, create a new task, point the task to the bat file and schedule. Easy Cheesy
Yes, you may need to set authority settings to highest level so that users may run it.
ASKER
I would like the task run from a windows server. Is there any difference?
No. but make sure authority is good.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent video.
I don't know if this is possible. I have a folder where a pdf file is loaded . My program reads into that folder and executes it and process the file. The folder receives this file once a month. Is it possible to schedule the batch file to run everyday to execute it even on the days that no pdf file exists in that folder? And also once the pdf file is run delete the file or move it to another folder.
I don't know if this is possible. I have a folder where a pdf file is loaded . My program reads into that folder and executes it and process the file. The folder receives this file once a month. Is it possible to schedule the batch file to run everyday to execute it even on the days that no pdf file exists in that folder? And also once the pdf file is run delete the file or move it to another folder.
I think you may get an error in the scheduler if no input exists.
ASKER
I'm not sure what day in a month a file will be drop in the folder to process. Can it execute conditionally only if a file/input is present to read? Any ideas to handle this?
You would have to put some batch file checking in place.
Here is some batch file checking to model after (Clear Reliability History)
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
Here is some batch file checking to model after (Clear Reliability History)
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
ASKER
I don't know what this batch file does. Can you add comment as a guide for me to follow?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> Excellent video.
Thank you, Zach — I appreciate the compliment. Thanks, too, for endorsing it — also appreciated!
> Is it possible to schedule the batch file to run everyday to execute it even on the days that no pdf file exists in that folder?
Sure! You're describing what is commonly known as a Watched Folder. Many commercial programs have a Watched Folder feature, such as Nuance's Power PDF Advanced. I show its Watched Feature in this other 5-minute EE video Micro Tutorial:
Convert Scanned Image-Only PDF Files to PDF Searchable Image Files via OCR with Power PDF Advanced
I have written many custom programs with a Watched Folder feature. It's fine if no input files exist in the Watched Folder — the program simply exits, or waits for a specified amount of time before checking again for files that came into the Watched Folder (depends on how you want to implement it).
> And also once the pdf file is run delete the file or move it to another folder.
Yes, a very common feature in programs that process a Watched Folder. I strongly prefer moving a processed file into another folder — much safer than deleting it, as you'll have access to the original file in case processing went awry. My custom programs typically let the user specify three folders: the Watched Folder, also known as the Source Folder, which contains the source (input) files; the Destination Folder, where the output files are stored; and the AlreadyProcessed Folder, where the input files are moved after they have been processed. Regards, Joe
Thank you, Zach — I appreciate the compliment. Thanks, too, for endorsing it — also appreciated!
> Is it possible to schedule the batch file to run everyday to execute it even on the days that no pdf file exists in that folder?
Sure! You're describing what is commonly known as a Watched Folder. Many commercial programs have a Watched Folder feature, such as Nuance's Power PDF Advanced. I show its Watched Feature in this other 5-minute EE video Micro Tutorial:
Convert Scanned Image-Only PDF Files to PDF Searchable Image Files via OCR with Power PDF Advanced
I have written many custom programs with a Watched Folder feature. It's fine if no input files exist in the Watched Folder — the program simply exits, or waits for a specified amount of time before checking again for files that came into the Watched Folder (depends on how you want to implement it).
> And also once the pdf file is run delete the file or move it to another folder.
Yes, a very common feature in programs that process a Watched Folder. I strongly prefer moving a processed file into another folder — much safer than deleting it, as you'll have access to the original file in case processing went awry. My custom programs typically let the user specify three folders: the Watched Folder, also known as the Source Folder, which contains the source (input) files; the Destination Folder, where the output files are stored; and the AlreadyProcessed Folder, where the input files are moved after they have been processed. Regards, Joe
ASKER
nice! Read the watched folder but how does it implement this with the windows batch file when executing it..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm open to any opportunity that will produce the best output and a great job. I've appreciate the suggestion but if any solutions
that best fit is absolutely welcome.
that best fit is absolutely welcome.
ASKER
Also a challenge would be, what is a wrong file was drop in the folder the batch program reads from(not pdf for example) or a pdf but not the format program is expecting. How to error trap this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, the original question was answered beyond satisfaction, however I felt that what I need is a scripting solution that will be plug to a task scheduler. I'm looking for some conditional coding for checks and error trapping; questions upcoming to my future post. Thanks for your help
You're welcome, Zach, and thanks back at you for closing this question. Good luck with your scripting solution! Regards, Joe