I have lots of hard disk drives in my computer (7).
When they are not used the power option send them to sleep after a while. But because everything makes a lot of noise I would like to send them to sleep when I want, not just after the default system timeout.
On Windows (XP and up), preferably in C#,
How can I send a disk to sleep by code?
Thanks a lot in advance for your help...
I do not know of the API to do this directly but there are tools that can do it. One that I have seen is Hard Disk Sleeper. I have not used it on my own machines so I cannot speak to its quality or effectiveness.
It is possible to do this if you send ATA commands directly to a drive using IOCTL_ATA_PASS_THROUGH. You will need to pass the SLEEP command.
I don't think that this is a project for C# though.
AFAIK, this is an ATA command that sets the *spin down time8 - meaning it's the drive itself that shuts down. You could use IOCTL_ATA_PASS_THROUGH to send commands directly to the drive - but I'm afraid you'd do no better than just setting it to some min value (which I don't know what it is, but it should be in the ATA specs).
Edit: Looks like the venerable hdparm supports it, so it must be in the ATA spec:
-y Force an IDE drive to immediately enter the low power consumption standby mode, usually causing it to spin down.
-Y Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shut down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver will automatically handle issuing a reset if/when needed).
Since hdparm (and the underlying Linux kernel it uses to communicate with the drive) is GPL - you should be able to crib the specifics from there if you don't have an ATA spec handy.
Or, just use the win32 port.
On windows you can simply use "GetDevicePowerState" function returning FALSE if the drive is sleeping (not rotating).
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getdevicepowerstate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With