简体   繁体   English

通过代码,我怎样才能让硬盘驱动器进入睡眠状态

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

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...非常感谢您的帮助...

On windows you can simply use "GetDevicePowerState" function returning FALSE if the drive is sleeping (not rotating).在 Windows 上,如果驱动器处于睡眠状态(不旋转),您可以简单地使用“GetDevicePowerState”函数返回 FALSE。

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getdevicepowerstate https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getdevicepowerstate

I do not know of the API to do this directly but there are tools that can do it.我不知道直接执行此操作的 API,但有一些工具可以执行此操作。 One that I have seen is Hard Disk Sleeper .我见过的一种是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 .如果您使用IOCTL_ATA_PASS_THROUGH将 ATA 命令直接发送到驱动器,则可以执行此操作 You will need to pass the SLEEP command.您将需要传递 SLEEP 命令。

I don't think that this is a project for C# though.不过,我不认为这是 C# 的项目。

AFAIK, this is an ATA command that sets the *spin down time8 - meaning it's the drive itself that shuts down. AFAIK,这是一个 ATA 命令,用于设置 *spin down time8 - 这意味着它是驱动器本身关闭。 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).您可以使用 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. -Y 强制 IDE 驱动器立即进入最低功耗睡眠模式,使其完全关闭。 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).在可以再次访问驱动器之前需要硬复位或软复位(如果/在需要时,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 端口

I honestly don't think it is possible to do that by using only C# (ie the .NET framework).老实说,我认为仅使用 C#(即 .NET 框架)是不可能做到的。

Regardless, I would start by learning about WMI and ACPI .无论如何,我将从学习WMIACPI 开始

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 电源管理功能开始,尽管我认为它不允许控制单个硬盘驱动器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM