Problem with Coding a .bat file using TASKLIST Command

ando

New member
Joined
Oct 26, 2023
Messages
2
Reaction score
0
I want to initiate a ROBOCOPY process if EXCEL is running in my System.

To do this, I have created the following .txt file –
_________________________________________________________________________________________________________________________________________________________________
echo off

tasklist /fi "IMAGENAME eq *excel*" /fi "STATUS eq running"

if errorlevel 1 (exit)

( robocopy c:\users\neil\AAWorkingModules d:\excelSynch\%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%%time:~6,2%\ /e /b /xx /xo /copyall /xf ~$*.* /im /mot:5 /np /log+:d:\excelSynch\log\%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log )

exit
__________________________________________________________________________________________________________________________________________________________________

N.B. The ROBOCOPY process works exactly as I want – tested separately.

I then created a .bat file from this .txt file, and a Shortcut for the .bat file.

My Task Scheduler job then runs that Shortcut.

However, the TASKLIST process does not work – i.e. whether or not EXCEL is running, the ROBOCOPY command is not executed.

The scheduled process keeps running until it is ended manually in Task Scheduler.

Please help with corrections for my coding of the TASKLIST process, or any other errors I have made.
 

Xploit Machine

Well-known member
Joined
Nov 29, 2022
Messages
783
Reaction score
73
Try this ..

echo off
robocopy c:\users\neil\AAWorkingModules d:\excelSynch\%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%%time:~6,2%\ /e /b /xx /xo /copyall /xf ~$*.* /im /mot:5 /np /log+:d:\excelSynch\log\%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%%time:~6,2%.log )
exit
  • Search for and open "Computer Management"
  • Expand "Task Scheduler"
  • Right-click inside the tasks list and choose "Create New Task"
1698302125043.png
  • Create a new trigger
  • Select when you want the task to begin, "On a schedule" is a good option to start
  • Change the Settings to how often you want to run the task and when (date and time) you want it to start and reoccur
  • Advanced settings allow some additional options
  • Click OK when finished to create the task
1698302182889.png
  • Create a new action
  • Action: Choose "Start a program"
  • Settings: Program/script: "C:\temp\robocopy-example.bat"
  • This is telling Windows to run "C:\temp\robocopy-example.bat" in Windows command prompt. Change the path and filename inside the quotes to match where your script is located and what it is named. It is recommended to keep the path/filename short and avoid spaces.
1698302248554.png

Full instruction is here if needed ..
 

Vote:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dell desktop Memory Integrity problem 1
WIFI Problem at Windows 11 0
E-mail Problems 6
USB problems 3
Problems with SMTP 1
Onedrive problem 2
Email problems 6
Power plan management problem with laptop 1

Top