Batch file to keep HDD awake


If like me you have a bunch of external HDDs connected to your system, you are probably facing a similar irritant. External HDDs are configured in firmware to switch to low-power mode within a few minutes if idle. In this mode, the disk spins down and eventually stops. Accessing the disk causes a slight delay as the HDD must spin up again to full-speed and locate the sector on which your data is located.

Apart from the delay, the spinning up of the HDD spindle and raising of the head from it’s parking position to the data area of the disk causes significant clatter and mechanical wear and tear. The S.M.A.R.T. values also get incremented it appears that the HDD was being abused with repeated unplugging and plugging.

More often than not, the low power mode is activated within 1 – 3 minutes. So if you play a MP3 file from the HDD, the OS will read the entire file in a few seconds, load the data into RAM cache and pass it to the default music player application. From this moment, the HDD is idle. Hence before the song is over, the HDD would have entered into deep-sleep. As the song ends and the next one has to be loaded, you will hear the clatter of the HDD spinning up.

Since most HDD manufacturers also do not give any tools to configure this behaviour, the only way to keep the HDD spinning at full-speed will be to either read or write to it before the idle-timeout is reached.

There are utilities that perform a similar function, but it seemed like an overkill to me when you could simple use a batch-file to do the same.

The code below simply writes the current time to a temporary file. It then uses the CHOICE command to wait 15 seconds before writing the time again to the same file. The waiting time can be changed from 15 seconds to any value that is lower than the HDD’s idle-timeout duration. The batch file can be interrupted at any time by pressing “N” key or Ctrl-C.

Save this file as “NoSleep.bat” on the root directory of your HDD and launch it. Minimize the command-prompt window in which the batch file output is displayed.

The batch file should work on WinXP or higher systems without any issues. I have tested it to work on my Windows 10 laptop.


@echo off
:SECA
echo %time% >> .\delme.txt
choice /C YN /D Y /T 15 /M "%time% - Continue Yes, No"
set MyError=%ERRORLEVEL%
if %MyError% EQU 1 goto SECA
echo "Exiting batch file"
del .\delme.txt
goto OUT
:OUT
echo Good Bye!


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.