Disabling automatic defragmentation (schtasks)

laywee

New Member
1707441909625.png
schtasks /Change /DISABLE /TN "\Microsoft\Windows\Defrag\ScheduledDefrag"

I use this command to disable the defragmentation schedule, it works, but the first time I restart after installing the system, the schedule turns on again. How to fix it?
 
Try setting the task to disabled in the NTlite tasks page, so that it is in effect out of the box, rather than post-install. Also, here's a related discussion on defrag, trim, and SSD (link).
 
Last edited:
That's the right command, but I tested if Windows changed the setting.

Post-Setup (Machine):
Code:
schtasks /Change /DISABLE /TN "\Microsoft\Windows\Defrag\ScheduledDefrag"
schtasks /query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log1.txt
Post-Setup (User):
Code:
schtasks /query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log2.txt

Code:
C:\>more log1.txt

Folder: \Microsoft\Windows\Defrag
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
ScheduledDefrag                          N/A                    Disabled

C:\>more log2.txt

Folder: \Microsoft\Windows\Defrag
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
ScheduledDefrag                          N/A                    Disabled

After first reboot: Disabled.
After installing Updates, and reboot: Disabled.
 
That's the right command, but I tested if Windows changed the setting.

Post-Setup (Machine):
Code:
schtasks /Change /DISABLE /TN "\Microsoft\Windows\Defrag\ScheduledDefrag"
schtasks /query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log1.txt
Post-Setup (User):
Code:
schtasks /query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log2.txt

Code:
C:\>more log1.txt

Folder: \Microsoft\Windows\Defrag
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
ScheduledDefrag                          N/A                    Disabled

C:\>more log2.txt

Folder: \Microsoft\Windows\Defrag
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
ScheduledDefrag                          N/A                    Disabled

After first reboot: Disabled.
After installing Updates, and reboot: Disabled.
Unfortunately, it doesn't work for me.
 
Did you try the three commands, from Post-Setup? If both logs say "Disabled", your problem is happening outside of NTLite.
 
Did you try the three commands, from Post-Setup? If both logs say "Disabled", your problem is happening outside of NTLite.
I didn't fully understand how to organize it all with log files. Why do you need 2 identical ones? Thank you in advance.
 
1st log confirms that "schtasks /Disable" works as you requested, during Post-Setup (Machine).
2nd log confirms again the task is Disabled, during Post-Setup (User).

If both files report "Disabled", then whatever happened to re-enable the task wasn't part of Post-Setup. This would suggest it was triggered by something else you later installed, or was pushed by Windows Update (?).
 
1st log confirms that "schtasks /Disable" works as you requested, during Post-Setup (Machine).
2nd log confirms again the task is Disabled, during Post-Setup (User).

If both files report "Disabled", then whatever happened to re-enable the task wasn't part of Post-Setup. This would suggest it was triggered by something else you later installed, or was pushed by Windows Update (?).
And how to implement it correctly? Why exactly 2 different files with the same content?
 
The point is basic troubleshooting: you run a command and immediately check if that command worked or not. Then we check again later if anything changed its setting. There are two opportunities to confirm, in Machine and User phases, by logging the /query to separate files.

If you don't log the task's state, then we can't go back and understand what's happening.

Machine commands:
schtasks/Change /DISABLE /TN "\Microsoft\Windows\Defrag\ScheduledDefrag"
schtasks/query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log_Machine.txt

User commands:
schtasks/query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log_User.txt
 
The point is basic troubleshooting: you run a command and immediately check if that command worked or not. Then we check again later if anything changed its setting. There are two opportunities to confirm, in Machine and User phases, by logging the /query to separate files.

If you don't log the task's state, then we can't go back and understand what's happening.

Machine commands:
schtasks/Change /DISABLE /TN "\Microsoft\Windows\Defrag\ScheduledDefrag"
schtasks/query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log_Machine.txt

User commands:
schtasks/query /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" > C:\log_User.txt
1707511720849.png
Here is the result. I also noticed some nonsense with the language, although I did not touch the localization.
Вкл = On)
 
I can't read Russian (or Ukranian), and machine translation of this screen image doesn't work. Does it say "Disabled"?
Your defrag Control Panel has no UAC icons next to each button. Why is that?

1707515383956.png
 
I can't read Russian (or Ukranian), and machine translation of this screen image doesn't work. Does it say "Disabled"?
Your defrag Control Panel has no UAC icons next to each button. Why is that?

View attachment 11281
There are no UAC icons since I have disabled it completely. It says that it is disabled. I also can't figure out what's wrong with the text in the log files, it's not displayed correctly.
 
You have some other problem. schtasks /query says "Disabled".

View attachment 11282

Defrag is not scheduled. This is from a clean W11 23H2 install.

View attachment 11283
1707567137542.png
The console display is correct, but the status is "ready". The service starts only after the first reboot, it is initially disabled.

Below is a screenshot from the clean installation of the official image. There is also a problem with the display.
1707568234989.png
 
Last edited:
Back
Top