My program performs a task on the hard disk free space.
The task is quite long, it takes 1-2 hours.
The problem is that on laptop the hard disk may be turned off after few minutes when the user is inactive.
How do I programmatically prevent Windows from hard disk spin down (power off) ?
To prevent the system from entering idle mode you may try to use the
SetThreadExecutionStatefunction. This function informs the system that the application is in use and allows you to specify the thread’s execution requirements. The usage can be like this, but I’m not sure if this affects also the disk power down timer:Or there is also available the new set of functions
PowerCreateRequest,PowerSetRequestandPowerClearRequestdesigned for Windows 7, but the documentation is confusing and I haven’t found any example of their usage at this time.Or you can modify the power settings by
PowerWriteACValueIndexorPowerWriteDCValueIndexfunctions with theGUID_DISK_SUBGROUPsubgroup of power settings.