views:

1005

answers:

4

Hello, 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...

A: 

I honestly don't think it is possible to do that by using only C# (i.e. the .NET framework).

Regardless, I would start by learning about WMI and ACPI.

This tends to be the sort of thing that requires you to delve into a lower level language (at least to figure out the API calls to use with P\Invoke) because it usually involves interacting closely with the Operating System or possibly directly with a driver.

Maybe you could start by investigating the Windows Power Management Functions although I don't think it allows control of the individual hard drives.

Miky Dinescu
While there may not be a native C# way to do this, there is a high likelihood it can still be controlled from C# via PInvoke or COM interop.
Robert Paulson
Yes, I made a correction. What I wanted to say is that it is likely you'll have to look for a solution in native C++ and then port the implementation to C# using P\Invoke.
Miky Dinescu
last time I checked setpowerstate with wmi it said it's not implemented.also, you are right, it seems I cannot control individual drives with the power mangement functions. or at least I don't know how to do it.Last, I'm taking a solution in any language if I don't have the choice...
Jonx
+1  A: 

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.

Jack Bolding
the tool dates from the 99's and it looks like it's a shareware (read, cannot be used any more) but thanks I prefer code...
Jonx
Also looks limited to IDE/EIDE drives.
sean e
Maybe I have a hint here :http://smartmontools.sourceforge.net/http://hdparm-win32.dyndns.org/hdparm/unfortunately, I'm stuck as it seems that my disks can't use that stuff as they are RAID and it needs smart/ata/sata disks or specific RAID treatment.
Jonx
+1  A: 

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.

Dave Ganger
any sample of how to use this? in any language ;) the msdn page does not help much... shall this be used in drivers or can it be use in user mode programs?
Jonx
+1  A: 

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.

Mark Brackett
That also means it will only work with ata/sata disks and the like?Thanks for the notice that the disk shuts down by itself and that you can only set the down time...
Jonx
Yes - it's only for ATA drives. If you have SCSI, I think you'd need to send a SCSI Stop Unit command. Linux has scsi-tools and scsi-idle for this.
Mark Brackett