Spin Down Hard Disk Programmatically on Windows?

℡╲_俬逩灬. 提交于 2019-12-02 19:08:17

I hope this helps:

This: http://msdn.microsoft.com/en-us/library/aa394173%28VS.85%29.aspx

Leads to this: http://msdn.microsoft.com/en-us/library/aa394132%28VS.85%29.aspx#properties

Then, you can browse to this: http://msdn.microsoft.com/en-us/library/aa393485(v=VS.85).aspx

This documentation seems to outline what you are looking for I think.

P.S. Just trying to help, don't shoot the messanger.

Have you tried WMI? Based on MSDN documentation, you should be able to send spindown command to HDD via WMI:

http://msdn.microsoft.com/en-us/library/aa393493%28v=VS.85%29.aspx

uint32 SetPowerState(
  [in]  uint16 PowerState,
  [in]  datetime Time
);

EDIT:

This code lists all drives in system and drives that support this API:

strServer = "."

Set objWMI = GetObject("winmgmts://" & strServer & "/root\cimv2")
rem Set objInstances = objWMI.InstancesOf("CIM_DiskDrive",48)
Set objInstances = objWMI.ExecQuery("Select * from CIM_DiskDrive",,48) 
On Error Resume Next
For Each objInstance in objInstances
    With objInstance
        WScript.Echo Join(.Capabilities, ", ")
        WScript.Echo Join(.CapabilityDescriptions, ", ")
        WScript.Echo .Caption
        WScript.Echo .PNPDeviceID
        WScript.Echo "PowerManagementCapabilities: "  & .PowerManagementCapabilities
        WScript.Echo "PowerManagement Supported: " & .PowerManagementSupported
        WScript.Echo .Status
        WScript.Echo .StatusInfo
    End With
On Error Goto 0
Next

Just save this code as a .vbs file and run that from command line.

While there is no apparent way to do what you're asking for (i.e. tell power management "act as if the timer for spinning down the disk has expired"), there may be a couple ways to simulate it:

  1. Call FlushFileBuffers on the drive (you need to be elevated to open \\.\C), then issue the STANDBY command to the drive.

  2. Make the API call that sets the timeout for spinning down the disk to 1 second, then increase it back to its former value after 1 second. Note that you may need to ramp up to the former value rather than immediately jump to it.

I do not have an answer to the specific question that Mehrdad asked.

However, to help others who find this page when trying to figure out how to get their disk to standby when it should but doesn't:

  1. I found that on a USB disk, MS PwrTest claims that the disk is off, but actually it is still spinning. This occurs even with really short global disk timeouts in win 7. (This implies that even if the system thinks it has turned the disk off, it might not actually be off. Consequently, Mehrdad's original goal might not work even if the correct way to do it is found. This may relate to how various USB disk controllers implement power state.)

  2. I also found that the program HDDScan successfully can turn off the disk, and can successfully set a timeout value that the disk honors. Also, the disk spins up when it is accessed by the OS, a good thing if you need to use it, but not so good if you are worrying about it spinning up all the time to flush 1kB buffers. (I chose to set the idle timeout in HDDScan to 1 minute more than the system power manager timeout. This hopefully assures that the system will not think the disk is spun up when it is not.)

I note that powercfg has an option to prevent the idle clock from restarting from small infrequent disk writes. (Called "burst ignore time.")

You can get HDDScan here: HDDScan.com and PwrTest here: Windows Driver Kit. Unfortunately, the PwrTest thing forces you to have a lot of other MS stuff installed first, but it is all free if you can figure out how to download it from their confusing web pages.

I believe the Devcon Command line utility should be able to accomplish what you need to do. If it does - the source code is available in the Windows Ddk.

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