Processes in Microsoft 365 for setting up Office apps, redeeming product keys, and activating licenses.
Hello
I’m Adeyemi and I’d be happy to help you with your question.
I understand that you're trying to run a ROBOCOPY process if EXCEL is running on your system, and you're having trouble with the TASKLIST command in your .bat file. Here's a way to check if EXCEL is running using the TASKLIST command:
tasklist /FI "IMAGENAME eq EXCEL.EXE" 2>NUL | find /I /N "EXCEL.EXE">NUL
if "%ERRORLEVEL%"=="0" (
REM Your robocopy command here
)
This script checks if any Excel file is open or running. If Excel is running, the error level will be 0, and the commands inside the parentheses will be executed. You can replace REM Your robocopy command here with your ROBOCOPY command.
If you're still having issues, it might be due to how you're calling the .bat file in Task Scheduler. When setting up the task in Task Scheduler, try configuring it to execute cmd.exe. In the arguments field, put /c path_to_your_bat_file > path_to_your_log_file 2>&1. This will execute your .bat file and output any errors to a log file, which can help with troubleshooting.
Please replace path_to_your_bat_file with the actual path to your .bat file, and path_to_your_log_file with the path where you want to save the log file. For example:
/c C:\YourFolderName\BackupProg.bat > C:\YourFolderName\BackupProg.log 2>&1
I hope this helps
Give back to the Community. Help the next person who has this issue by indicating if this reply solved your problem. Click Yes or No below
Regards Adeyemi