Best MyDefrag (formerly JkDefrag) Scripts for Desktop and Server DrivesMyDefrag (formerly JkDefrag) is a fast, flexible, and scriptable disk defragmentation tool for Windows. Though its original developer stopped active development years ago, MyDefrag remains valuable because of its lightweight engine and powerful scripting capabilities. Proper scripts let you tailor defragmentation behavior for different environments — a casual desktop, a workstation with mixed workloads, or a busy file server. This article explains how MyDefrag scripting works, recommends scripts for desktop and server drives, explains why specific settings matter, shows example scripts you can copy and adapt, and offers tips for scheduling, safety, and troubleshooting.
Quick overview: What MyDefrag scripts do and why they matter
MyDefrag operates by reading a script that defines groups (file placement), rules for movement and consolidation, and scheduling behavior. Unlike “one-click” defragmenters with fixed heuristics, MyDefrag scripts let you:
- Define where file types are placed on the disk (start, middle, end of volume).
- Control how aggressively to consolidate free space.
- Exclude files or folders (pagefile, temp folders) from reordering.
- Balance speed against thoroughness through pass selection (fast, normal, intensive).
- Optimize for specific workloads (e.g., many small files vs. few large files).
A well-designed script improves system responsiveness, reduces fragmentation-induced I/O overhead on servers, and minimizes unnecessary I/O on SSDs (which generally should not be defragmented).
Desktop-focused scripts
Desktop machines benefit from placing frequently used system and application files near the start of the disk (where seek times are lowest), consolidating free space for future file creation, and minimizing reorganization of large infrequently accessed media files.
Why these choices
- Move OS and program files to the fastest area.
- Keep personal media and archives toward the end; less frequent movement conserves I/O.
- Moderate consolidation reduces fragmentation without long maintenance windows.
Recommended desktop scripts
Below are three sample scripts tailored for typical desktop use. Each is accompanied by a brief explanation and configuration notes. Copy into a .mys file and run with MyDefrag.
- Balanced Desktop — good overall performance vs. run time “`js // BalancedDesktop.mys – Balanced desktop optimization // Places OS/Programs at front, user files in middle, large media at end, // and does a moderate free-space consolidation.
VolumeAnalyze(); MoveFilesToStartOfVolume(”.exe”, “.dll”, “C:\Windows*”); MoveFilesToStartOfVolume(“C:\Program Files*”); MoveFilesToMiddleOfVolume(“C:\Users*\Documents*”, “C:\Users*\Desktop*”); MoveFilesToEndOfVolume(“C:\Users*\Music*”, “C:\Users*\Videos*”, “C:\Users*\Pictures*”); OptimizeFreeSpace(consolidationLevel = 2); // 0 = none, 1 = light, 2 = moderate, 3 = intensive
Notes: Adjust globs and paths for nonstandard user directories. Moderation avoids long runs on large drives. 2) Fast Desktop — short runs, improves responsiveness quickly ```js // FastDesktop.mys - Fast pass for desktops VolumeAnalyze(); MoveFilesToStartOfVolume("C:\Windows\**", "C:\Program Files\**"); ConsolidateSmallFiles(); // quick small-file consolidation OptimizeFreeSpace(consolidationLevel = 1);
Notes: Use for scheduled short maintenance (weekly). Avoid heavy movement of media.
- Thorough Desktop — weekly deep optimization
// ThoroughDesktop.mys - Full optimization, best when run infrequently VolumeAnalyze(); MoveFilesToStartOfVolume("C:\Windows\**", "C:\Program Files\**", "C:\Users\**\AppData\**"); MoveFilesToMiddleOfVolume("C:\Users\**\Documents\**", "C:\Users\**\Desktop\**"); MoveFilesToEndOfVolume("C:\Users\**\Music\**", "C:\Users\**\Videos\**", "C:\Users\**\Pictures\**", "*.iso", "*.zip"); OptimizeFreeSpace(consolidationLevel = 3); DefragAllFiles(); // thorough pass, may run hours on large drives
Notes: Run during off-hours; exclude large temp or cache folders if desired.
Server-focused scripts
Servers have different needs: consistent low-latency I/O, minimal downtime, and I/O operations that can’t be heavily delayed. On transactional servers (database, mail), defragmentation risks interfering with performance and can be counterproductive unless coordinated. For file servers, focusing on consolidating free space and avoiding moving live database or VM files is key.
General server guidance
- Avoid defragmenting live database/VM files while those applications are running; instead, schedule maintenance windows.
- Focus on file-server workloads: consolidate free space, place frequently accessed files in efficient locations, and limit movement during business hours.
- Use light/passive scripts during business hours; use deeper scripts in maintenance windows.
Recommended server scripts
- Quiet Server — low-impact optimization during business hours
// QuietServer.mys - minimal-impact defrag for production hours VolumeAnalyze(); MoveFilesToStartOfVolume("**/*.lnk", "**/*.exe", "**/*.dll"); // small system files ConsolidateSmallFiles(); OptimizeFreeSpace(consolidationLevel = 1); ExcludePaths("C:\Databases\**", "C:\VMs\**"); // avoid moving active DB/VM files
Notes: Excluding DB and VM dirs prevents lock and corruption risks.
- Maintenance Window — deeper pass for after-hours
// MaintenanceServer.mys - deeper optimization during maintenance windows VolumeAnalyze(); ExcludePaths("C:\Databases\**\*.mdf", "C:\VMs\**\*.vhd*", "C:\Backups\**"); MoveFilesToStartOfVolume("C:\Program Files\**", "C:\Windows\**"); MoveFilesToMiddleOfVolume("C:\Shared\Documents\**"); MoveFilesToEndOfVolume("C:\Archive\**"); OptimizeFreeSpace(consolidationLevel = 3); DefragAllFiles();
Notes: Adjust excludes for your data file types. Test on a staging server first.
- Large File Server — minimize movement of very large files
// LargeFileServer.mys - Avoid moving huge media/backup files, consolidate for new files VolumeAnalyze(); ExcludeFilesBySize(minSizeMB = 1024); // don't move files >= 1GB MoveFilesToStartOfVolume("**/*.exe", "**/*.dll", "C:\System\**"); OptimizeFreeSpace(consolidationLevel = 2);
Notes: Many backup/media servers store immutable content; moving large files wastes time and I/O.
SSDs and MyDefrag — special considerations
- Do not defragment SSDs with MyDefrag; they do not benefit from traditional defragmentation and excessive writes reduce their lifespan. Use Windows built-in TRIM support and the OS’s optimization tool instead.
- MyDefrag scripts should exclude SSD volumes entirely. Example:
// SkipSSD.mys - exclude SSD drive letters ExcludePaths("C:\", "D:\"); // only use for HDDs; remove SSD paths
Instead of defragmenting, ensure TRIM is enabled and rely on OS maintenance.
Best practices, scheduling, and safety
- Always exclude volatile system files or active database/VM images unless you schedule downtime.
- Test new scripts on a non-production volume first.
- Keep regular, light maintenance (weekly or biweekly) and deeper passes monthly or quarterly depending on churn and drive size.
- Monitor disk I/O and surface health (SMART) before running large defrag operations on older drives.
- Combine MyDefrag with file-organization strategies: move user archives to separate volumes, store VM images on dedicated volumes, and use quotas to reduce fragmentation.
Troubleshooting common issues
- Long run times: reduce consolidation level, exclude very large files, or run a faster script.
- High disk I/O during business hours: use the Quiet Server script and limit runs to off-hours.
- Locked files: schedule defrags when services using those files are stopped, or exclude them.
- Disk errors: run chkdsk before defragmentation.
Example script library (copy-and-adapt)
- BalancedDesktop.mys (copy from above)
- FastDesktop.mys
- ThoroughDesktop.mys
- QuietServer.mys
- MaintenanceServer.mys
- LargeFileServer.mys
Customize globs, paths, file-size thresholds, and exclusion lists to your environment.
Conclusion
MyDefrag remains a powerful tool for administrators and power users who want precise control over file placement and defragmentation behavior. The right script depends on your workload: desktops benefit from placing OS and apps near the start of disk and moderate free-space consolidation; servers require cautious, low-impact passes during business hours and deeper maintenance in windows. Always exclude SSDs and active database/VM files and test scripts in a safe environment before deploying widely.
Leave a Reply