Solved Task Scheduler - Log Files, Output, etc.

Ilya

New member
Local time
2:21 PM
Messages
15
Location
Albany, NY
Hi guys and gals,

I'm trying to accomplish something at work and need some help.

Here is the situation:

1) There is a scheduled task setup to run an 'import' for my companies software. This task runs a .bat file which runs a program with a few switches (application 1). I have edited the .bat file to output to a log file.
2) However, after the program starts and does it's thing, it closes and launches another application (application 2) and does some more work on the newly imported data (actually integrates it into the database). BUT, because application 1 closed, the task considers itself closed and closes the .bat file and marks itself complete.

My issue is:

How do I write a .bat file or reprogram my scheduled task so my output file/log file includes the entire process? My goal is to keep an eye on how long the process runs from start to finish. Because they run in the middle of the night, I'm not around to monitor. The 'history' tab in Task Scheduler only shows the start/stop time of the initial program, not the second one.

This runs on Server 2008, but 2008 is very similar to W7, so your solutions should apply to both.

Thanks for any help you can give me!

EDIT:

Solution: See post #3.
 
Last edited:

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 10 Professional x64
CPU
Intel Core i7 4770k
Motherboard
Asus Z97-Pro(Wi-Fi ac)
Memory
32GB Crucial Ballistix DDR3-1600
Graphics Card(s)
4GB Gigabyte NVidia GTX 980
Sound Card
Creative Labs Sound Blaster Audigy 5/Rx
Monitor(s) Displays
40" Samsung 1080p LED LCD TV
Screen Resolution
1920x1080
Hard Drives
500GB - Samsung SSD 850 EVO (OS)
6TB - Western Digital SATA 6.0 WD6001FZWX-00A2VA0 (Data)
PSU
EVGA SuperNova 1000 P2
Case
Corsair 760T White ATX Full Tower Case
Cooling
Noctua NH-C14
Keyboard
Logitech K350
Mouse
Logitech M705
Internet Speed
Timewarner/Spectrum - Extreme (50/5)
Antivirus
Windows Defender
Browser
Chrome
Anyone? Please?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 10 Professional x64
CPU
Intel Core i7 4770k
Motherboard
Asus Z97-Pro(Wi-Fi ac)
Memory
32GB Crucial Ballistix DDR3-1600
Graphics Card(s)
4GB Gigabyte NVidia GTX 980
Sound Card
Creative Labs Sound Blaster Audigy 5/Rx
Monitor(s) Displays
40" Samsung 1080p LED LCD TV
Screen Resolution
1920x1080
Hard Drives
500GB - Samsung SSD 850 EVO (OS)
6TB - Western Digital SATA 6.0 WD6001FZWX-00A2VA0 (Data)
PSU
EVGA SuperNova 1000 P2
Case
Corsair 760T White ATX Full Tower Case
Cooling
Noctua NH-C14
Keyboard
Logitech K350
Mouse
Logitech M705
Internet Speed
Timewarner/Spectrum - Extreme (50/5)
Antivirus
Windows Defender
Browser
Chrome
Since no one helped, I worked on it and got my own solution. Sharing this for anyone else who comes across this, because I'm nice. :mad:

Again...here is a brief explanation of what is going on:

  1. Scheduled task kicks off Program 1
  2. After Program 1 is done running, it automatically kicks off Program 2. HOWEVER, after Program 1 closes, task scheduler thinks the process is complete when it actually isn't. Thus, logging/history in the Task Scheduler is not accurate.
  3. Program 2 runs. My method monitors for Program 2 to close, and then ends the log file...thus providing me a way to see the entire process from beginning to end.

Code:
:: Setting the time and date - ** DO NOT CHANGE **
set tday=%date:~-4%%date:~4,2%%date:~7,2%

:: Setting the company name - replace with the company name
set company=Sample

:: Setting the log file folder location - Shouldn't need to change
set logfilefolder=C:\log\%company%

:: Creating above folder if it doesn't exist - ** DO NOT CHANGE **
IF NOT EXIST "%logfilefolder%" MKDIR "%logfilefolder%

:: Setting the log file name - replace with company name
set logfilename=Logname_%tday%.txt

:: Setting the location of PROGRAM1.exe - shouldn't change
set ProAdminLoc=C:\PROGRAM1.exe

:: Setting the name of the Auto INI - replace with correct INI filename
set autoini=TFSampleAuto.ini

:: Setting the switches to use (archive, import, export, etc.) - replace as needed
set switches=/autoarchive /autoimport



echo ************************************************************************************************** > "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo   **** %company% Auto Archive and Auto Import/Export Process Started: %DATE% %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo ************************************************************************************************** >> "%logfilefolder%\%logfilename%"

echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  // company Name: %company% // >> "%logfilefolder%\%logfilename%"
echo  // Auto INI Name: %autoini% // >> "%logfilefolder%\%logfilename%"

echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Availability Check] Checking to see if a previous archive or import is running before starting a new process **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Checking to see if a previous import is running before starting a new process

:: Checking for another instance of PROGRAM1.exe

:PRVARCHSTART
tasklist /FI "IMAGENAME eq PROGRAM1.exe" | find /I "PROGRAM1.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another archive process is not running...checking for an import/export process... **** >> "%logfilefolder%\%logfilename%"
goto PRVARCHEND
) ELSE (
echo        **** %TIME% - Another archive is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto PRVARCHSTART
)
:PRVARCHEND

:: Checking for another instance of PROGRAM2.exe

:PRVIMPSTART
tasklist /FI "IMAGENAME eq PROGRAM2.exe" | find /I "PROGRAM2.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another import/export process is not running...starting archive process... **** >> "%logfilefolder%\%logfilename%"
goto PRVIMPEND
) ELSE (
echo        **** %TIME% - Another import/export is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto PRVIMPSTART
)
:PRVIMPEND

echo     **** Step completed at: %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Archive] Running PROGRAM1.exe with following switches: %switches% **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Running PROGRAM1.exe with necessary switches

"%ProAdminLoc%" %autoini% %switches% >> "%logfilefolder%\%logfilename%"

:ARCHSTART
tasklist /FI "IMAGENAME eq PROGRAM1.exe" | find /I "PROGRAM1.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another archive process is not running...starting import/export process... **** >> "%logfilefolder%\%logfilename%"
goto ARCHEND
) ELSE (
echo        **** %TIME% - Another archive is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto ARCHSTART
)
:ARCHEND

echo     **** Step completed at: %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Import/Export] PROGRAM2.exe launching...monitoring PROGRAM2.exe for completion **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Checking to see if PROGRAM2.exe is running

:IMPEXPSTART
tasklist /FI "IMAGENAME eq PROGRAM2.exe" | find /I "PROGRAM2.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another import/export process is not running...ending auto archive/import/export process... **** >> "%logfilefolder%\%logfilename%"
goto IMPEXPEND
) ELSE (
echo        **** %TIME% - Import/export is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto IMPEXPSTART
)
:IMPEXPEND

end

BOOMSHAKALAKA!
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 10 Professional x64
CPU
Intel Core i7 4770k
Motherboard
Asus Z97-Pro(Wi-Fi ac)
Memory
32GB Crucial Ballistix DDR3-1600
Graphics Card(s)
4GB Gigabyte NVidia GTX 980
Sound Card
Creative Labs Sound Blaster Audigy 5/Rx
Monitor(s) Displays
40" Samsung 1080p LED LCD TV
Screen Resolution
1920x1080
Hard Drives
500GB - Samsung SSD 850 EVO (OS)
6TB - Western Digital SATA 6.0 WD6001FZWX-00A2VA0 (Data)
PSU
EVGA SuperNova 1000 P2
Case
Corsair 760T White ATX Full Tower Case
Cooling
Noctua NH-C14
Keyboard
Logitech K350
Mouse
Logitech M705
Internet Speed
Timewarner/Spectrum - Extreme (50/5)
Antivirus
Windows Defender
Browser
Chrome
Hi I'm an engineering student and I don't have much background related to log files but I'm trying to create one for my final year project. I am just trying to understand your code to develop my own one.
Can you tell me which is your first task and which is your second task? I mean the name of the function will do. I will try to understand the rest from your answer.
Thank you so much sir.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
i5
OS
Windows 7 Ultimate x64
Antivirus
Avast
Browser
Google Chrome
Hi I'm an engineering student and I don't have much background related to log files but I'm trying to create one for my final year project. I am just trying to understand your code to develop my own one.
Can you tell me which is your first task and which is your second task? I mean the name of the function will do. I will try to understand the rest from your answer.
Thank you so much sir.

Hi there.

I'm not using functions but am using pointers or GOTO flags inside of basic loops to move around and repeat things (if necessary). These are referenced by the single ":", as double ":" ( :: ) are just comments.

For example, I first check to make sure that both programs I'm going to monitor are not still running from a previous task. If they are, I send the command to kill them and keep looping until I no longer see them.

Hopefully that helps...
 
Last edited:

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 10 Professional x64
CPU
Intel Core i7 4770k
Motherboard
Asus Z97-Pro(Wi-Fi ac)
Memory
32GB Crucial Ballistix DDR3-1600
Graphics Card(s)
4GB Gigabyte NVidia GTX 980
Sound Card
Creative Labs Sound Blaster Audigy 5/Rx
Monitor(s) Displays
40" Samsung 1080p LED LCD TV
Screen Resolution
1920x1080
Hard Drives
500GB - Samsung SSD 850 EVO (OS)
6TB - Western Digital SATA 6.0 WD6001FZWX-00A2VA0 (Data)
PSU
EVGA SuperNova 1000 P2
Case
Corsair 760T White ATX Full Tower Case
Cooling
Noctua NH-C14
Keyboard
Logitech K350
Mouse
Logitech M705
Internet Speed
Timewarner/Spectrum - Extreme (50/5)
Antivirus
Windows Defender
Browser
Chrome
Thank you so much for your fast reply sir ! :)
It helps a lot. :thumbsup:
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
i5
OS
Windows 7 Ultimate x64
Antivirus
Avast
Browser
Google Chrome
Back
Top