How to run ForFiles in Task Scheduler


rdwray

Well-known member
Member
VIP
Local time
7:44 AM
Posts
223
OS
Windows 11 Pro; 21H2, Build 22000.1281
This will run in Task Scheduler and deletes the file, the problem is that it never stops running so none of the other tasks will run.

Code:
cmd.exe /c ForFiles /P "C:\Users\user\Desktop" /s /m "mpam-fe.exe" /c "cmd /c del @FILE"
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Pro; 21H2, Build 22000.1281AMD Ryzen 3 3250 with Radeon Graphics8gbAMD Graphics
OS
Windows 11 Pro; 21H2, Build 22000.1281
Computer type
Laptop
Manufacturer/Model
Dell 3525
CPU
AMD Ryzen 3 3250 with Radeon Graphics
Memory
8gb
Graphics Card(s)
AMD Graphics
Sound Card
AMD high definition audio device; Realtek audio
Screen Resolution
1980x1020
mpam-fe.exe might be a protected file, and you need to confirm deletion.
Code:
cmd.exe /c ForFiles /P "C:\Users\dellr\Desktop" /s /m "mpam-fe.exe" /c "cmd /c del /f @FILE"
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
mpam-fe.exe might be a protected file, and you need to confirm deletion.
Code:
cmd.exe /c ForFiles /P "C:\Users\user\Desktop" /s /m "mpam-fe.exe" /c "cmd /c del /f @FILE"
Still keeps running and I moved the /f to several locations. I also tried the following and get the same result:
cmd.exe /c del /f "C:\Users\user\Desktop\mpam-fe.exe"
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Pro; 21H2, Build 22000.1281AMD Ryzen 3 3250 with Radeon Graphics8gbAMD Graphics
OS
Windows 11 Pro; 21H2, Build 22000.1281
Computer type
Laptop
Manufacturer/Model
Dell 3525
CPU
AMD Ryzen 3 3250 with Radeon Graphics
Memory
8gb
Graphics Card(s)
AMD Graphics
Sound Card
AMD high definition audio device; Realtek audio
Screen Resolution
1980x1020
I confirmed that, it looks like Task Scheduler thinks the command never exited. May need to debug this, since running the exact line in CMD completes as expected.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
What I think you're seeing, is if you don't right-menu Refresh in the Task Scheduler -- it won't update the view to reflect the task has completed.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
This is not a real solution, but a workaround. I restart the PC every night so I just placed the command before the restart. Funny part is that you can have many tasks running at the same time without any problem.
 

My Computer My Computer

At a glance

Windows 11 Pro; 21H2, Build 22000.1281AMD Ryzen 3 3250 with Radeon Graphics8gbAMD Graphics
OS
Windows 11 Pro; 21H2, Build 22000.1281
Computer type
Laptop
Manufacturer/Model
Dell 3525
CPU
AMD Ryzen 3 3250 with Radeon Graphics
Memory
8gb
Graphics Card(s)
AMD Graphics
Sound Card
AMD high definition audio device; Realtek audio
Screen Resolution
1980x1020
What is copying mpam-fe.exe to your Desktop? Maybe it's got an open file lock, and preventing your script from exiting. A reboot would kill the process holding the lock.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
What is copying mpam-fe.exe to your Desktop? Maybe it's got an open file lock, and preventing your script from exiting. A reboot would kill the process holding the lock.
mpam-fe. is Defender security update and I use Task Scheduler to download (using Firefox) and install the update; didn't notice it before, but the install process continues to run also so the nightly restart is shutting down that process also.
 

My Computer My Computer

At a glance

Windows 11 Pro; 21H2, Build 22000.1281AMD Ryzen 3 3250 with Radeon Graphics8gbAMD Graphics
OS
Windows 11 Pro; 21H2, Build 22000.1281
Computer type
Laptop
Manufacturer/Model
Dell 3525
CPU
AMD Ryzen 3 3250 with Radeon Graphics
Memory
8gb
Graphics Card(s)
AMD Graphics
Sound Card
AMD high definition audio device; Realtek audio
Screen Resolution
1980x1020
That probably explains it. I would just use PowerShell instead, and not depend on a browser.
Replace your task command with "powershell" / "[...]"
Code:
powershell "$File='C:\Users\GARLIN\Desktop\mpam-fe.exe'; $ProgressPreference='silentlyContinue'; wget 'https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64' -OutFile $File; Start-Process $File -Wait"
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
That probably explains it. I would just use PowerShell instead, and not depend on a browser.
Replace your task command with "powershell" / "[...]"
Code:
powershell "$File='C:\Users\GARLIN\Desktop\mpam-fe.exe'; $ProgressPreference='silentlyContinue'; wget 'https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64' -OutFile $File; Start-Process $File -Wait"
Thanks for the info, I do have a couple of tasks that I use powershell for some of them.
 

My Computer My Computer

At a glance

Windows 11 Pro; 21H2, Build 22000.1281AMD Ryzen 3 3250 with Radeon Graphics8gbAMD Graphics
OS
Windows 11 Pro; 21H2, Build 22000.1281
Computer type
Laptop
Manufacturer/Model
Dell 3525
CPU
AMD Ryzen 3 3250 with Radeon Graphics
Memory
8gb
Graphics Card(s)
AMD Graphics
Sound Card
AMD high definition audio device; Realtek audio
Screen Resolution
1980x1020

Latest Support Threads

Back
Top Bottom