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.