By code, how can I send a hard disk drive to sleep

扶醉桌前 提交于 2019-12-06 01:38:59

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/860986/by-code-how-can-i-send-a-hard-disk-drive-to-sleep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!