Author |
Topic: Control HDD power ON/OFF from BB4W? (Read 1114 times) |
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Control HDD power ON/OFF from BB4W?
« Thread started on: Nov 30th, 2009, 04:09am » |
|
I found this on MSDN ... Each device in the system has its own power states, and these are independently managed by the device driver (or other policy owner) while the system is in the working state. The device's policy integrates any particular application's needs with device capabilities and other operating system information to conserve energy without adversely affecting the work that the user is doing. For example, if the communications port is not opened by an application, there is no reason for the hardware to be consuming energy, and turning it off will not adversely affect the user. When an application opens the port, the user wants to use it, so the driver must turn it back on in a way that is transparent to the user. ... but I failed to find out how to do it, and I'm really interested in powering down HDDs anyway! Can we access Win API param.s from BB4W so as to switch off selected (!) HDD. I would very much like to write a wrapper to do this. I have two pairs of RAID 0 which only have intermittent use whereas two PCs run 24/7 doing number crunching for Stanford Molecular Dynamics Group, which do not need access to those drives. It seems a crying shame to have the 4 SATA drives wearing themselves out to no good purpose. It is extremely tedious to carefully shut down seven different 24/7 app.s, just so I can power off, open the case and dis/reconnect the SATAs. Any pointers anybody? --Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #1 on: Nov 30th, 2009, 08:43am » |
|
Quote:When an application opens the port, the user wants to use it, so the driver must turn it back on in a way that is transparent to the user. ... but I failed to find out how to do it |
|
Just because a driver can change the power state of the hardware it controls, it doesn't follow that a user program can! Remember that a driver is operating in kernel mode, with many more privileges (and a largely different API) from what a user-mode program has access to.
Quote:Can we access Win API param.s from BB4W so as to switch off selected (!) HDD |
|
You may want to investigate the Power Management API:
http://msdn.microsoft.com/en-us/library/aa373163.aspx
(Later) there's some code here (e.g. message #4):
http://www.codeguru.com/forum/showthread.php?t=463853
This is C++, but should be relatively easily ported to BB4W.
Richard.
|
« Last Edit: Nov 30th, 2009, 09:07am by admin » |
Logged
|
|
|
|
dynamic35
New Member
member is offline


Gender: 
Posts: 34
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #2 on: Jul 7th, 2011, 6:43pm » |
|
On very hot summer days this kind of code may save a PC while performing extreme mathematics all the day MODE 8 PRINT "Save energy & allow yr PC sleep at warm summer nights "; FNgetwindowtext PRINT "Time=";TIME$ SYS "LoadLibrary", "powrprof.dll" TO powrprof% SYS "GetProcAddress", powrprof%, "SetSuspendState" TO `SetSuspendState` REM Lets perform /extreme/ mathematics with duration of many days... s1=0:s2=0 FOR i= 1 TO 101:s1=s1+1:NEXT i PRINT "Day 1 results s1=";s1 PRINT "PC starts to sleep at .............. "; TIME$ SYS `SetSuspendState`, 0, 1, 0 REM process continues as soon as user hit a key PRINT "Thanks & G morning, you hit me up at "; TIME$ PRINT " Yesterday resulted s1= "; s1 FOR i= 102 TO 200:s2=s2+1:NEXT i summa=s1+s2 PRINT " Day 2 results s2= ";s2, PRINT " Grand TOTAL sofar= "; summa END DEF FNgetwindowtext LOCAL text% DIM text% LOCAL 255 SYS "GetWindowText", @hwnd%, text%, 256 = $$text% RGS Dynamic-35 from Lapland
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #3 on: Jul 9th, 2011, 12:00am » |
|
Thanks dynamic tiger, that sounds promising.
I am very ignorant about sys calls, so if I cannot find it in WinAPI I am stuck. Where can I learn about the 3 parameters you are sending in {SYS `SetSuspendState`, 0, 1, 0}.
Can I use some variation of this to suspend only specified drives (including a RAID 0 pair)?
--G
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
dynamic35
New Member
member is offline


Gender: 
Posts: 34
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #4 on: Jul 9th, 2011, 4:32pm » |
|
on Jul 9th, 2011, 12:00am, 19Grumpah42 wrote:Thanks dynamic tiger, that sounds promising.
I am very ignorant about sys calls, ... --G |
|
(like most of us!) ) but we may study msdn.microsoft.com: BOOLEAN WINAPI SetSuspendState( __in BOOLEAN Hibernate, __in BOOLEAN ForceCritical, __in BOOLEAN DisableWakeEvent );
Parameters Hibernate [in] If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.
ForceCritical [in] This parameter has no effect.
Windows Server 2003, Windows XP, and Windows 2000: If this parameter is TRUE, the system suspends operation immediately; if it is FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation. DisableWakeEvent [in] If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.
Return Value If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks The calling process must have the SE_SHUTDOWN_NAME privilege. To enable the SE_SHUTDOWN_NAME privilege, use the AdjustTokenPrivileges function. For more information, see Changing Privileges in a Token.
An application may use SetSuspendState to transition the system from the working state to the standby (sleep), or optionally, hibernate (S4) state. This function is similar to the SetSystemPowerState function.
For more information on using PowrProf.h, see Power Schemes. For information about events that can wake the system, see System Wake-up Events.
{SYS `SetSuspendState`, 1, 0, 0}.
saves maximal amount of kilowatts (hibernites)
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #5 on: Jul 10th, 2011, 02:09am » |
|
Thanks for the above, that was encouraging, perhaps I am getting the idea about how to read msdn descriptions. Lots more to embrace, obviously. --G
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
Richard Russell
Guest
|
 |
Re: Control HDD power ON/OFF from BB4W?
« Reply #6 on: Jul 14th, 2011, 09:10am » |
|
Don't forget that API Viewer will provide the BB4W translations of many API calls. It's not simply a tool for finding the values of Windows Constants (in which respect it has been superseded by the Windows Constants add-in utility).
If you haven't already done so, download and install API Viewer and its BB4W plug-in, then checkout the translation it gives of the API(s) you are interested in.
Tools are there to be used!!!!
Richard.
|
|
Logged
|
|
|
|
|