How to Run ROBOCOPY Only When Excel Is Running via Batch File
Question details
Execute a ROBOCOPY backup command within a Windows batch file only if the Microsoft Excel application is currently running.

- Product
- Microsoft Excel
- Device & OS
- Windows
- Scenario
- Automating file backups using ROBOCOPY and Task Scheduler while restricting the backup job to only trigger when an Excel instance is active.
- Observed behavior
- The user requires a batch script condition to detect the EXCEL.EXE process, alongside Task Scheduler configurations that prevent the job from remaining active indefinitely or failing without logs.
Ensure you have basic knowledge of creating Windows batch (.bat) files and possess administrative privileges to configure Windows Task Scheduler.
Create a Conditional Batch File Using TASKLIST
Use the TASKLIST and FIND commands within your script to check for the EXCEL.EXE process before allowing ROBOCOPY to execute.
Windows batch scripts can use system commands to check active processes. By filtering the active tasks for EXCEL.EXE, you can set a condition that only triggers your ROBOCOPY command if the process is found.
Open Notepad or your preferred text editor to begin creating your batch script.
Type the command: TASKLIST /FI "IMAGENAME eq excel.exe" | find /i "excel.exe" > nul. This silently checks if Excel is currently running in the background.
On the next line, evaluate the error level by typing: IF %ERRORLEVEL% EQU 0 (ROBOCOPY "C:\SourceFolder" "D:\BackupFolder" /MIR). Replace the source and destination paths with your actual directories.
Go to File > Save As, choose 'All Files' from the dropdown, and save the document as 'excel_backup.bat'.

Configure Task Scheduler with Logging
Set up Task Scheduler to execute the batch file correctly via cmd.exe, and redirect output to a log file to prevent silent failures.
Try WPS Office for Your Spreadsheet Needs
While configuring advanced automation for your files, consider managing your spreadsheets with WPS Office. It provides a lightweight, robust, and completely free alternative to Microsoft Office.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for Windows.
- 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheets to easily open, edit, and save your existing .xlsx or .xls files without losing formatting.

Frequently Asked Questions
Why does my Task Scheduler job remain running indefinitely?
This usually happens when the batch script encounters an error that prompts for user input (like a confirmation prompt), which cannot be seen in the background. Redirecting standard output to a log file (using > log.txt 2>&1) will help you identify the hidden prompt.
Can I use this script to check if WPS Spreadsheets is running instead of Excel?
Yes. To detect WPS Spreadsheets, simply replace 'excel.exe' with 'et.exe' in the TASKLIST command filter within your batch script. The rest of the conditional logic remains identical.
Does TASKLIST check if a specific workbook is open?
No, TASKLIST only checks whether the overall application process (EXCEL.EXE) is active in memory. It cannot determine which specific spreadsheet files are currently open.




