According to the code, how can I send a hard drive for sleep

I have many hard drives on my computer (7).

When not in use, the power setting sends them to sleep after a while. But since everything makes a lot of noise, I would like to send them to sleep whenever I want, and not just after the default timeout.

On Windows (XP and above), preferably in C #,

How can I send the drive to sleep by code?

Thank you for your help...

+6
c # windows hardware
source share
4 answers

I do not know the API for this, but there are tools that can do this. I saw that Hard Disk Sleeper . I did not use it on my machines, so I can not talk about its quality or effectiveness.

+1
source share

This can be done if you send ATA commands directly to disk using IOCTL_ATA_PASS_THROUGH . You will need to pass the SLEEP command.

I don't think this is a project for C #.

+1
source share

AFAIK, this is an ATA command that sets the time * spin down8 - this means that the disk itself is turning off. You can use IOCTL_ATA_PASS_THROUGH to send commands directly to disk, but I'm afraid you are no better than just setting it to some minimum value (that I don't know what it is, but it should be in the ATA specifications).

Edit: Looks like the venerable hdparm supports it , so it should be in the ATA specification:

-y Force the IDE to immediately enter low-power standby mode, usually causing it to spin.

-Y Force the IDE to immediately go into sleep mode with low power consumption, causing it to shut down completely. A hard or soft reset is required before re-accessing the disk (the Linux IDE driver will automatically handle reset output if necessary).

Since hdparm (and the underlying Linux kernel that it uses to communicate with the drive) is the GPL - you should be able to use features from there if you don't have the ATA specification.

Or just use the win32 port .

+1
source share

I honestly do not think that this can be done using only C # (i.e. the .NET framework).

Regardless, I would start by exploring WMI and ACPI .

This is usually the thing that requires you to learn a lower level language (at least to determine the API calls to use with P \ Invoke), since it usually involves close interaction with the operating system or, possibly, directly with the driver .

Perhaps you can start by exploring the Windows power management features , although I don't think it allows you to manage individual hard drives.

0
source share

All Articles