通过代码,我如何发送硬盘驱动器进入睡眠状态

时间:2022-10-11 03:23:06

I have lots of hard disk drives in my computer (7).

我的电脑里有很多硬盘(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#,

在Windows(XP及更高版本)上,最好是在C#中,

How can I send a disk to sleep by code?

如何通过代码将磁盘发送到睡眠状态?

Thanks a lot in advance for your help...

非常感谢您的帮助......

4 个解决方案

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

我不知道直接执行此操作的API,但有些工具可以执行此操作。我见过的就是Hard Disk Sleeper。我没有在我自己的机器上使用它,所以我不能说它的质量或效果。

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

如果使用IOCTL_ATA_PASS_THROUGH将ATA命令直接发送到驱动器,则可以执行此操作。您需要传递SLEEP命令。

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

我不认为这是C#的项目。

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

AFAIK,这是一个ATA命令,用于设置*关闭时间8 - 这意味着它是关闭的驱动器本身。你可以使用IOCTL_ATA_PASS_THROUGH直接向驱动器发送命令 - 但是我担心你做的不仅仅是将它设置为某个最小值(我不知道它是什么,但它应该在ATA规范中) )。

Edit: Looks like the venerable hdparm supports it, so it must be in the ATA spec:

编辑:看起来像古老的hdparm支持它,所以它必须在ATA规范中:

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

-y强制IDE驱动器立即进入低功耗待机模式,通常会导致其停止运转。

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

-Y强制IDE驱动器立即进入功耗最低的睡眠模式,使其完全关闭。在再次访问驱动器之前,需要进行硬重置或软重置(如果需要,Linux IDE驱动程序将自动处理发出重置)。

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.

由于hdparm(以及它用于与驱动器通信的底层Linux内核)是GPL - 如果您没有方便的ATA规范,您应该可以从那里获取详细信息。

Or, just use the win32 port.

或者,只需使用win32端口。

#4


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

老实说,我不认为只使用C#(即.NET框架)就可以做到这一点。

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

无论如何,我将首先了解WMI和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.

这往往需要您深入研究较低级别的语言(至少要弄清楚要与P \ Invoke一起使用的API调用),因为它通常涉及与操作系统密切交互,或者可能直接与驱动程序交互。

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

也许您可以从调查Windows电源管理功能开始,尽管我认为它不允许控制单个硬盘驱动器。

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

我不知道直接执行此操作的API,但有些工具可以执行此操作。我见过的就是Hard Disk Sleeper。我没有在我自己的机器上使用它,所以我不能说它的质量或效果。

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

如果使用IOCTL_ATA_PASS_THROUGH将ATA命令直接发送到驱动器,则可以执行此操作。您需要传递SLEEP命令。

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

我不认为这是C#的项目。

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

AFAIK,这是一个ATA命令,用于设置*关闭时间8 - 这意味着它是关闭的驱动器本身。你可以使用IOCTL_ATA_PASS_THROUGH直接向驱动器发送命令 - 但是我担心你做的不仅仅是将它设置为某个最小值(我不知道它是什么,但它应该在ATA规范中) )。

Edit: Looks like the venerable hdparm supports it, so it must be in the ATA spec:

编辑:看起来像古老的hdparm支持它,所以它必须在ATA规范中:

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

-y强制IDE驱动器立即进入低功耗待机模式,通常会导致其停止运转。

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

-Y强制IDE驱动器立即进入功耗最低的睡眠模式,使其完全关闭。在再次访问驱动器之前,需要进行硬重置或软重置(如果需要,Linux IDE驱动程序将自动处理发出重置)。

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.

由于hdparm(以及它用于与驱动器通信的底层Linux内核)是GPL - 如果您没有方便的ATA规范,您应该可以从那里获取详细信息。

Or, just use the win32 port.

或者,只需使用win32端口。

#4


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

老实说,我不认为只使用C#(即.NET框架)就可以做到这一点。

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

无论如何,我将首先了解WMI和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.

这往往需要您深入研究较低级别的语言(至少要弄清楚要与P \ Invoke一起使用的API调用),因为它通常涉及与操作系统密切交互,或者可能直接与驱动程序交互。

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

也许您可以从调查Windows电源管理功能开始,尽管我认为它不允许控制单个硬盘驱动器。