Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Even if the powersaving feature of Windows is set to never shut down my harddrive, my external USB harddrives will still spin themselves down automatically after some period of inactivity. The problem with that is they will spin back up randomly while the computer is idle or while watching a movie / listening to music; it's really very annoying (not only because of the noise it makes but also because it needlessly stresses the drive each time it does that, which is more than a dozen times a day and that worries me). I have come across an old freeware utility that can be used to tackle this annoyance very effectively with SATA / eSATA drives. It's called revoSleep. The documentation of this utility reveals the trick is to bring the disk offline, spin it down, then disable its device driver.

This inspired me to look for a similar solution for USB drives, but so far I have been unable to find a software utility that works without any problems. Using diskpart, I am able to bring my USB disk offline. Next, using a freeware utility called HDDScan for Windows (similar to 'hdparm'), I can spin down the disk and I can even do so from a batchfile. Nice.

The final step is to disable the device driver of the disk, from within the same batchfile instead of using Device Manager. Using another freeware utility called DevCon, I was quickly able to identify the correct device driver. It turns out the old version of DevCon (from 2003) cannot disable device drivers on Windows 7 or 8. So I ended up downloading the Driver Developmet Kit (DDK) 7.1.0 from Microsoft's Download Center to grab the version that works. Once that was settled, finally I was able to disable the device driver of my USB harddrive. Now here comes my question. Wat's the best aka most reliable way to automate these steps in a batchfile (or a WSH script or whatever) so that the batchfile / script won't accidentally choose the wrong drive for any of the commands that it will execute?

FWIW, I came across this post, but the sample code only uses the first 11 characters of a volume label to find a partition number. Instead, I want it to use (if possible) a harddrive's unique serial number to find a disk number, to be able to bring the correct disk offline.

share|improve this question
Shouldn't you try and figure out why the drive's randomly spinning up? Something (a service etc.) must be causing it - maybe you can tackle this at the source instead of jumping through hoops. – Karan Dec 27 '12 at 23:42
Using Sysintenal's Process Monitor, I can see that the process that's causing it is usually Svchost or something like that; it's never a process that I am able to easily relate to anything other than the OS itself, really. – willy Dec 28 '12 at 0:00

This may help.

If you know the serial number of the HDD you can use the batch script below to get the drive letter. From there you could use the drive letter to discover the volume or disk number using diskpart.

@echo off
setlocal EnableDelayedExpansion

set "xDrive="
rem Loop through all of the drives to find the external HDD
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S"
    if "%xSerial%"=="ABCD-1234" (
        set "xDrive=%%~D:"

echo Drive Found = %xDrive%

share|improve this answer
Thanks, but I found out that the serial number of a HDD isn't necessarily unique and that, even though collisions are probably rare, there is a better way to find the correct disk number. – willy Jan 9 '13 at 23:48
Assuming $diid is a string which holds the device instance ID of the HDD, $disks = gwmi win32_diskdrive | ? pnpdeviceid -eq $diid $c = @($disks).count if ($c -eq 1) { $diskid = $disks.index $dpscript = @" sel disk $diskid offline disk exit "@ $dpscript | diskpart } else { write-host "ERROR" } – willy Jan 9 '13 at 23:59
up vote 0 down vote accepted

I was able to write a PowerShell 3.0 script to bring my external USB HDD offline using Diskpart, then spin it down using HDDScan for Windows, and then finally disable its device driver using DevCon. However, the HDD spins back up after some minutes and immediately spins down again after that. I verified that this symptom occurs only once after my script was run. I will post a new question re this problem.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .