ReactOS  0.4.14-dev-77-gd9e7c48
powrprof.h File Reference
#include <ntsecapi.h>
Include dependency graph for powrprof.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _GLOBAL_MACHINE_POWER_POLICY
 
struct  _GLOBAL_USER_POWER_POLICY
 
struct  _GLOBAL_POWER_POLICY
 
struct  _MACHINE_POWER_POLICY
 
struct  _MACHINE_PROCESSOR_POWER_POLICY
 
struct  _USER_POWER_POLICY
 
struct  _POWER_POLICY
 

Macros

#define EnableMultiBatteryDisplay   2
 
#define EnablePasswordLogon   4
 
#define EnableSysTrayBatteryMeter   1
 
#define EnableWakeOnRing   8
 
#define EnableVideoDimDisplay   16
 
#define NEWSCHEME   (UINT)-1
 

Typedefs

typedef struct _GLOBAL_MACHINE_POWER_POLICY GLOBAL_MACHINE_POWER_POLICY
 
typedef struct _GLOBAL_MACHINE_POWER_POLICYPGLOBAL_MACHINE_POWER_POLICY
 
typedef struct _GLOBAL_USER_POWER_POLICY GLOBAL_USER_POWER_POLICY
 
typedef struct _GLOBAL_USER_POWER_POLICYPGLOBAL_USER_POWER_POLICY
 
typedef struct _GLOBAL_POWER_POLICY GLOBAL_POWER_POLICY
 
typedef struct _GLOBAL_POWER_POLICYPGLOBAL_POWER_POLICY
 
typedef struct _MACHINE_POWER_POLICY MACHINE_POWER_POLICY
 
typedef struct _MACHINE_POWER_POLICYPMACHINE_POWER_POLICY
 
typedef struct _MACHINE_PROCESSOR_POWER_POLICY MACHINE_PROCESSOR_POWER_POLICY
 
typedef struct _MACHINE_PROCESSOR_POWER_POLICYPMACHINE_PROCESSOR_POWER_POLICY
 
typedef struct _USER_POWER_POLICY USER_POWER_POLICY
 
typedef struct _USER_POWER_POLICYPUSER_POWER_POLICY
 
typedef struct _POWER_POLICY POWER_POLICY
 
typedef struct _POWER_POLICYPPOWER_POLICY
 
typedef BOOLEAN(CALLBACKPWRSCHEMESENUMPROC) (UINT, DWORD, LPWSTR, DWORD, LPWSTR, PPOWER_POLICY, LPARAM)
 
typedef BOOLEAN(CALLBACKPFNNTINITIATEPWRACTION) (POWER_ACTION, SYSTEM_POWER_STATE, ULONG, BOOLEAN)
 

Functions

NTSTATUS WINAPI CallNtPowerInformation (POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG)
 
BOOLEAN WINAPI CanUserWritePwrScheme (VOID)
 
BOOLEAN WINAPI DeletePwrScheme (UINT)
 
BOOLEAN WINAPI EnumPwrSchemes (PWRSCHEMESENUMPROC, LPARAM)
 
BOOLEAN WINAPI GetActivePwrScheme (PUINT)
 
BOOLEAN WINAPI GetCurrentPowerPolicies (PGLOBAL_POWER_POLICY, PPOWER_POLICY)
 
BOOLEAN WINAPI GetPwrCapabilities (PSYSTEM_POWER_CAPABILITIES)
 
BOOLEAN WINAPI GetPwrDiskSpindownRange (PUINT, PUINT)
 
BOOLEAN WINAPI IsAdminOverrideActive (PADMINISTRATOR_POWER_POLICY)
 
BOOLEAN WINAPI IsPwrHibernateAllowed (VOID)
 
BOOLEAN WINAPI IsPwrShutdownAllowed (VOID)
 
BOOLEAN WINAPI IsPwrSuspendAllowed (VOID)
 
BOOLEAN WINAPI ReadGlobalPwrPolicy (PGLOBAL_POWER_POLICY)
 
BOOLEAN WINAPI ReadProcessorPwrScheme (UINT, PMACHINE_PROCESSOR_POWER_POLICY)
 
BOOLEAN WINAPI ReadPwrScheme (UINT, PPOWER_POLICY)
 
BOOLEAN WINAPI SetActivePwrScheme (UINT, PGLOBAL_POWER_POLICY, PPOWER_POLICY)
 
BOOLEAN WINAPI SetSuspendState (BOOLEAN, BOOLEAN, BOOLEAN)
 
BOOLEAN WINAPI WriteGlobalPwrPolicy (PGLOBAL_POWER_POLICY)
 
BOOLEAN WINAPI WriteProcessorPwrScheme (UINT, PMACHINE_PROCESSOR_POWER_POLICY)
 
BOOLEAN WINAPI ValidatePowerPolicies (PGLOBAL_POWER_POLICY, PPOWER_POLICY)
 
BOOLEAN WINAPI WritePwrScheme (PUINT, LPWSTR, LPWSTR, PPOWER_POLICY)
 

Macro Definition Documentation

◆ EnableMultiBatteryDisplay

#define EnableMultiBatteryDisplay   2

Definition at line 15 of file powrprof.h.

◆ EnablePasswordLogon

#define EnablePasswordLogon   4

Definition at line 16 of file powrprof.h.

◆ EnableSysTrayBatteryMeter

#define EnableSysTrayBatteryMeter   1

Definition at line 17 of file powrprof.h.

◆ EnableVideoDimDisplay

#define EnableVideoDimDisplay   16

Definition at line 19 of file powrprof.h.

◆ EnableWakeOnRing

#define EnableWakeOnRing   8

Definition at line 18 of file powrprof.h.

◆ NEWSCHEME

#define NEWSCHEME   (UINT)-1

Definition at line 20 of file powrprof.h.

Typedef Documentation

◆ GLOBAL_MACHINE_POWER_POLICY

◆ GLOBAL_POWER_POLICY

◆ GLOBAL_USER_POWER_POLICY

◆ MACHINE_POWER_POLICY

◆ MACHINE_PROCESSOR_POWER_POLICY

◆ PFNNTINITIATEPWRACTION

typedef BOOLEAN(CALLBACK* PFNNTINITIATEPWRACTION) (POWER_ACTION, SYSTEM_POWER_STATE, ULONG, BOOLEAN)

Definition at line 95 of file powrprof.h.

◆ PGLOBAL_MACHINE_POWER_POLICY

◆ PGLOBAL_POWER_POLICY

◆ PGLOBAL_USER_POWER_POLICY

◆ PMACHINE_POWER_POLICY

◆ PMACHINE_PROCESSOR_POWER_POLICY

◆ POWER_POLICY

◆ PPOWER_POLICY

◆ PUSER_POWER_POLICY

◆ PWRSCHEMESENUMPROC

typedef BOOLEAN(CALLBACK* PWRSCHEMESENUMPROC) (UINT, DWORD, LPWSTR, DWORD, LPWSTR, PPOWER_POLICY, LPARAM)

Definition at line 94 of file powrprof.h.

◆ USER_POWER_POLICY

Function Documentation

◆ CallNtPowerInformation()

NTSTATUS WINAPI CallNtPowerInformation ( POWER_INFORMATION_LEVEL  ,
PVOID  ,
ULONG  ,
PVOID  ,
ULONG   
)

Definition at line 59 of file powrprof.c.

64 {
65  BOOLEAN old;
66 
67  //Lohnegrim: In order to get the right results, we have to adjust our Privileges
70 
71  return NtPowerInformation(InformationLevel,
72  lpInputBuffer,
73  nInputBufferSize,
74  lpOutputBuffer,
75  nOutputBufferSize);
76 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
unsigned char BOOLEAN
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define SE_CREATE_PAGEFILE_PRIVILEGE
Definition: security.c:669
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660

Referenced by Hib_SaveData(), IsBatteryUsed(), ProcessorDlgProc(), SetProcSpeed(), and test_CallNtPowerInformation().

◆ CanUserWritePwrScheme()

BOOLEAN WINAPI CanUserWritePwrScheme ( VOID  )

Definition at line 79 of file powrprof.c.

80 {
81  HKEY hKey = NULL;
82  LONG Ret;
83 
84  TRACE("()\n");
85 
87  if (Ret != ERROR_SUCCESS)
88  {
89  TRACE("RegOpenKeyEx failed: %d\n", Ret);
90  SetLastError(Ret);
91  return FALSE;
92  }
93 
94  RegCloseKey(hKey);
95  return TRUE;
96 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
static const WCHAR szPowerCfgSubKey[]
Definition: powrprof.c:38
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define KEY_WRITE
Definition: nt_native.h:1031
#define TRACE(s)
Definition: solgame.cpp:4
#define SetLastError(x)
Definition: compat.h:409
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CreateEnergyList(), and test_CanUserWritePwrScheme().

◆ DeletePwrScheme()

BOOLEAN WINAPI DeletePwrScheme ( UINT  )

Definition at line 99 of file powrprof.c.

100 {
101  WCHAR Buf[MAX_PATH];
102  UINT Current;
103  LONG Err;
104 
105  swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%d", uiIndex);
106 
107  if (!GetActivePwrScheme(&Current))
108  return FALSE;
109 
110  if (Current == uiIndex)
111  {
113  return FALSE;
114  }
115 
117  if (Err != ERROR_SUCCESS)
118  {
119  TRACE("RegDeleteKey failed: %d\n", Err);
120  SetLastError(Err);
121  return FALSE;
122  }
123 
124  return TRUE;
125 }
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
long LONG
Definition: pedump.c:60
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
Definition: powrprof.c:285
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
unsigned int UINT
Definition: ndis.h:50
#define RegDeleteKey
Definition: winreg.h:502

Referenced by DelScheme(), and test_DeletePwrScheme().

◆ EnumPwrSchemes()

BOOLEAN WINAPI EnumPwrSchemes ( PWRSCHEMESENUMPROC  ,
LPARAM   
)

Definition at line 219 of file powrprof.c.

221 {
222  HKEY hKey;
223  LONG Err;
224  DWORD dwSize, dwNameSize = MAX_PATH, dwDescSize = MAX_PATH, dwIndex = 0;
225  WCHAR szNum[3 + 1], szName[MAX_PATH], szDesc[MAX_PATH];
226  POWER_POLICY PwrPolicy;
227  USER_POWER_POLICY userPwrPolicy;
228  MACHINE_POWER_POLICY machinePwrPolicy;
229  BOOLEAN bRet = FALSE;
230 
231  if (!lpfnPwrSchemesEnumProc)
232  {
234  return FALSE;
235  }
236 
237  Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\PowerPolicies", 0, KEY_READ, &hKey);
238  if (Err != ERROR_SUCCESS)
239  {
240  ERR("RegOpenKeyW failed: %d\n", Err);
241  SetLastError(Err);
242  return FALSE;
243  }
244 
246 
247  dwSize = sizeof(szNum) / sizeof(WCHAR);
248 
249  while (RegEnumKeyExW(hKey, dwIndex, szNum, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
250  {
251  if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy,
252  dwNameSize, szName,
253  dwDescSize, szDesc))
254  {
255  WARN("POWRPROF_GetUserPowerPolicy failed\n");
256  goto cleanup;
257  }
258 
259  if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
260  {
261  WARN("POWRPROF_GetMachinePowerPolicy failed\n");
262  goto cleanup;
263  }
264 
265  memcpy(&PwrPolicy.user, &userPwrPolicy, sizeof(USER_POWER_POLICY));
266  memcpy(&PwrPolicy.mach, &machinePwrPolicy, sizeof(MACHINE_POWER_POLICY));
267 
268  if (!lpfnPwrSchemesEnumProc(_wtoi(szNum), (wcslen(szName) + 1) * sizeof(WCHAR), szName, (wcslen(szDesc) + 1) * sizeof(WCHAR), szDesc, &PwrPolicy, lParam))
269  goto cleanup;
270  else
271  bRet = TRUE;
272 
273  dwSize = sizeof(szNum) / sizeof(WCHAR);
274  dwIndex++;
275  }
276 
277 cleanup:
278  RegCloseKey(hKey);
280 
281  return bRet;
282 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
static const WCHAR szName[]
Definition: powrprof.c:45
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define WARN(fmt,...)
Definition: debug.h:111
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
MACHINE_POWER_POLICY mach
Definition: powrprof.h:92
USER_POWER_POLICY user
Definition: powrprof.h:91
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE PPRegSemaphore
Definition: powrprof.c:56
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:109
static BOOLEAN POWRPROF_GetUserPowerPolicy(LPWSTR szNum, PUSER_POWER_POLICY puserPwrPolicy, DWORD cchName, LPWSTR szName, DWORD cchDesc, LPWSTR szDesc)
Definition: powrprof.c:128
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
static BOOLEAN POWRPROF_GetMachinePowerPolicy(LPWSTR szNum, PMACHINE_POWER_POLICY pmachinePwrPolicy)
Definition: powrprof.c:185
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
char * cleanup(char *str)
Definition: wpickclick.c:99
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
LPARAM lParam
Definition: combotst.c:139
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by BuildSchemesList(), ShowPowerSchemesPopupMenu(), and test_EnumPwrSchemes().

◆ GetActivePwrScheme()

BOOLEAN WINAPI GetActivePwrScheme ( PUINT  )

Definition at line 285 of file powrprof.c.

286 {
287  HKEY hKey;
288  WCHAR szBuf[MAX_PATH];
289  DWORD dwSize;
290  LONG Err;
291 
292  TRACE("GetActivePwrScheme(%u)", puiID);
293 
294  Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg", 0, KEY_READ, &hKey);
295  if (Err != ERROR_SUCCESS)
296  {
297  ERR("RegOpenKey failed: %d\n", Err);
298  SetLastError(Err);
299  return FALSE;
300  }
301 
302  dwSize = sizeof(szBuf);
303  Err = RegQueryValueExW(hKey, L"CurrentPowerPolicy",
304  NULL, NULL,
305  (LPBYTE)&szBuf, &dwSize);
306  if (Err != ERROR_SUCCESS)
307  {
308  ERR("RegQueryValueEx failed: %d\n", Err);
309  RegCloseKey(hKey);
310  SetLastError(Err);
311  return FALSE;
312  }
313 
314  RegCloseKey(hKey);
315  *puiID = _wtoi(szBuf);
316 
317  return TRUE;
318 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by CreateEnergyList(), DeletePwrScheme(), GetCurrentPowerPolicies(), ShowPowerSchemesPopupMenu(), test_DeletePwrScheme(), test_GetCurrentPowerPolicies(), and test_GetSetActivePwrScheme().

◆ GetCurrentPowerPolicies()

BOOLEAN WINAPI GetCurrentPowerPolicies ( PGLOBAL_POWER_POLICY  ,
PPOWER_POLICY   
)

Definition at line 321 of file powrprof.c.

323 {
324  /*
325  SYSTEM_POWER_POLICY ACPower, DCPower;
326 
327  FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
328 
329  NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
330  NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
331 
332  return FALSE;
333  */
334 /*
335  Lohnegrim: I don't know why this Function should call NtPowerInformation, because as far as I know,
336  it simply returns the GlobalPowerPolicy and the AktivPowerScheme!
337  */
338  UINT uiID;
339 
340  if (pGlobalPowerPolicy != NULL)
341  {
342  if (!ReadGlobalPwrPolicy(pGlobalPowerPolicy))
343  return FALSE;
344  }
345  if (pPowerPolicy != NULL)
346  {
347  if (!GetActivePwrScheme(&uiID))
348  return FALSE;
349 
350  if (!ReadPwrScheme(uiID, pPowerPolicy))
351  return FALSE;
352  }
353 
354  return TRUE;
355 }
#define TRUE
Definition: types.h:120
BOOLEAN WINAPI ReadPwrScheme(UINT uiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:610
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
Definition: powrprof.c:285
BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:521
unsigned int UINT
Definition: ndis.h:50

Referenced by test_GetCurrentPowerPolicies(), test_ValidatePowerPolicies(), and test_ValidatePowerPolicies_Old().

◆ GetPwrCapabilities()

BOOLEAN WINAPI GetPwrCapabilities ( PSYSTEM_POWER_CAPABILITIES  )

Definition at line 358 of file powrprof.c.

359 {
361 
362  TRACE("(%p)\n", lpSystemPowerCapabilities);
363 
364  if (!lpSystemPowerCapabilities)
365  {
367  return FALSE;
368  }
369 
370  Status = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
371  if(!NT_SUCCESS(Status))
372  {
374  return FALSE;
375  }
376 
377  return TRUE;
378 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660

Referenced by Adv_InitDialog(), Applet1(), CreateEnergyList(), Hib_InitDialog(), Pos_InitData(), and test_GetPwrCapabilities().

◆ GetPwrDiskSpindownRange()

BOOLEAN WINAPI GetPwrDiskSpindownRange ( PUINT  ,
PUINT   
)

Definition at line 381 of file powrprof.c.

382 {
383  HKEY hKey;
384  BYTE lpValue[40];
385  LONG Ret;
386  DWORD cbValue = sizeof(lpValue);
387 
388  TRACE("(%p, %p)\n", RangeMax, RangeMin);
389 
390  if (RangeMax == NULL || RangeMin == NULL)
391  {
393  return FALSE;
394  }
395 
397 
399  if (Ret != ERROR_SUCCESS)
400  {
401  TRACE("RegOpenKeyEx failed: %d\n", Ret);
402  TRACE("Using defaults: 3600, 3\n");
403  *RangeMax = 3600;
404  *RangeMin = 3;
406  return TRUE;
407  }
408 
409  Ret = RegQueryValueExW(hKey, szDiskMax, 0, 0, lpValue, &cbValue);
410  if (Ret != ERROR_SUCCESS)
411  {
412  TRACE("Couldn't open DiskSpinDownMax: %d\n", Ret);
413  TRACE("Using default: 3600\n");
414  *RangeMax = 3600;
415  }
416  else
417  {
418  *RangeMax = _wtoi((LPCWSTR)lpValue);
419  }
420 
421  cbValue = sizeof(lpValue);
422 
423  Ret = RegQueryValueExW(hKey, szDiskMin, 0, 0, lpValue, &cbValue);
424  if (Ret != ERROR_SUCCESS)
425  {
426  TRACE("Couldn't open DiskSpinDownMin: %d\n", Ret);
427  TRACE("Using default: 3\n");
428  *RangeMin = 3;
429  }
430  else
431  {
432  *RangeMin = _wtoi((LPCWSTR)lpValue);
433  }
434 
435  RegCloseKey(hKey);
436 
438 
439  return TRUE;
440 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
static const WCHAR szPowerCfgSubKey[]
Definition: powrprof.c:38
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR szDiskMin[]
Definition: powrprof.c:49
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE PPRegSemaphore
Definition: powrprof.c:56
#define SetLastError(x)
Definition: compat.h:409
unsigned char BYTE
Definition: mem.h:68
static const WCHAR szDiskMax[]
Definition: powrprof.c:48
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define INFINITE
Definition: serial.h:102
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by test_GetPwrDiskSpindownRange().

◆ IsAdminOverrideActive()

BOOLEAN WINAPI IsAdminOverrideActive ( PADMINISTRATOR_POWER_POLICY  )

Definition at line 443 of file powrprof.c.

444 {
445  FIXME("( %p) stub!\n", p);
446  return FALSE;
447 }
#define FIXME(fmt,...)
Definition: debug.h:110
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by test_IsAdminOverrideActive().

◆ IsPwrHibernateAllowed()

BOOLEAN WINAPI IsPwrHibernateAllowed ( VOID  )

Definition at line 450 of file powrprof.c.

451 {
452  SYSTEM_POWER_CAPABILITIES PowerCaps;
454  BOOLEAN old;
455 
457 
458  Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
459  if (!NT_SUCCESS(Status))
460  {
462  return FALSE;
463  }
464 
465  return PowerCaps.SystemS4 && PowerCaps.HiberFilePresent; // IsHiberfilPresent();
466 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660

Referenced by ExitWindowsDialog(), GetAllowedShutdownOptions(), and wmain().

◆ IsPwrShutdownAllowed()

BOOLEAN WINAPI IsPwrShutdownAllowed ( VOID  )

Definition at line 469 of file powrprof.c.

470 {
471  SYSTEM_POWER_CAPABILITIES PowerCaps;
473  BOOLEAN old;
474 
476 
477  Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
478  if (!NT_SUCCESS(Status))
479  {
481  return FALSE;
482  }
483 
484  return PowerCaps.SystemS5;
485 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660

◆ IsPwrSuspendAllowed()

BOOLEAN WINAPI IsPwrSuspendAllowed ( VOID  )

Definition at line 488 of file powrprof.c.

489 {
490  SYSTEM_POWER_CAPABILITIES PowerCaps;
492  BOOLEAN old;
493 
495 
496  Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
497  if (!NT_SUCCESS(Status))
498  {
500  return FALSE;
501  }
502 
503  return PowerCaps.SystemS1 || PowerCaps.SystemS2 || PowerCaps.SystemS3;
504 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660

Referenced by ExitWindowsDialog(), and GetAllowedShutdownOptions().

◆ ReadGlobalPwrPolicy()

BOOLEAN WINAPI ReadGlobalPwrPolicy ( PGLOBAL_POWER_POLICY  )

Definition at line 521 of file powrprof.c.

522 {
523  GLOBAL_MACHINE_POWER_POLICY glMachPwrPolicy;
524  GLOBAL_USER_POWER_POLICY glUserPwrPolicy;
525  HKEY hKey = NULL;
526  DWORD dwSize;
527  LONG Err;
528  BOOL bRet = FALSE;
529 
531 
532  // Getting user global power policy
533  Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\GlobalPowerPolicy", 0, KEY_READ, &hKey);
534  if (Err != ERROR_SUCCESS)
535  {
536  ERR("RegOpenKeyW failed: %d\n", Err);
537  SetLastError(Err);
538  goto cleanup;
539  }
540 
541  dwSize = sizeof(glUserPwrPolicy);
542  Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glUserPwrPolicy, &dwSize);
543  if (Err != ERROR_SUCCESS)
544  {
545  ERR("RegQueryValueExW failed: %d\n", Err);
546  SetLastError(Err);
547  goto cleanup;
548  }
549 
550  RegCloseKey(hKey);
551 
552  // Getting machine global power policy
553  Err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy", 0, KEY_READ, &hKey);
554  if (Err != ERROR_SUCCESS)
555  {
556  ERR("RegOpenKeyW failed: %d\n", Err);
557  SetLastError(Err);
558  goto cleanup;
559  }
560 
561  dwSize = sizeof(glMachPwrPolicy);
562  Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glMachPwrPolicy, &dwSize);
563  if (Err != ERROR_SUCCESS)
564  {
565  ERR("RegQueryValueExW failed: %d\n", Err);
566  SetLastError(Err);
567  goto cleanup;
568  }
569 
570  memcpy(&pGlobalPowerPolicy->user, &glUserPwrPolicy, sizeof(GLOBAL_USER_POWER_POLICY));
571  memcpy(&pGlobalPowerPolicy->mach, &glMachPwrPolicy, sizeof(GLOBAL_MACHINE_POWER_POLICY));
572  bRet = TRUE;
573 
574 cleanup:
575  if(hKey)
576  RegCloseKey(hKey);
578 
579  return bRet;
580 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE PPRegSemaphore
Definition: powrprof.c:56
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERR(fmt,...)
Definition: debug.h:109
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
char * cleanup(char *str)
Definition: wpickclick.c:99
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by Adv_InitDialog(), Ala_InitData(), CreateEnergyList(), GetCurrentPowerPolicies(), and test_ReadGlobalPwrPolicy().

◆ ReadProcessorPwrScheme()

BOOLEAN WINAPI ReadProcessorPwrScheme ( UINT  ,
PMACHINE_PROCESSOR_POWER_POLICY   
)

Definition at line 584 of file powrprof.c.

586 {
587  HKEY hKey;
590 
591  swprintf(szPath, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\ProcessorPolicies\\%i", uiID);
593  return FALSE;
594 
595  if (RegQueryValueExW(hKey, szPolicies, NULL, 0, (LPBYTE)pMachineProcessorPowerPolicy, &dwSize) == ERROR_SUCCESS)
596  {
597  RegCloseKey(hKey);
598  return TRUE;
599  }
600 
601  RegCloseKey(hKey);
602  if (uiID != 0)
603  return ReadProcessorPwrScheme(0, pMachineProcessorPowerPolicy);
604 
605  return FALSE;
606 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN WINAPI ReadProcessorPwrScheme(UINT uiID, PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
Definition: powrprof.c:584
static const WCHAR szPolicies[]
Definition: powrprof.c:44
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define RegOpenKeyEx
Definition: winreg.h:520
LPCWSTR szPath
Definition: env.c:35
struct _MACHINE_PROCESSOR_POWER_POLICY MACHINE_PROCESSOR_POWER_POLICY
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by ReadProcessorPwrScheme(), and test_ReadProcessorPwrScheme().

◆ ReadPwrScheme()

BOOLEAN WINAPI ReadPwrScheme ( UINT  ,
PPOWER_POLICY   
)

Definition at line 610 of file powrprof.c.

612 {
613  USER_POWER_POLICY userPwrPolicy;
614  MACHINE_POWER_POLICY machinePwrPolicy;
615  WCHAR szNum[16]; // max number - 999
616 
618 
619  swprintf(szNum, L"%d", uiID);
620 
621  if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy, 0, NULL, 0, NULL))
622  {
624  return FALSE;
625  }
626 
627  if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
628  {
630  return FALSE;
631  }
632 
633  memcpy(&pPowerPolicy->user, &userPwrPolicy, sizeof(userPwrPolicy));
634  memcpy(&pPowerPolicy->mach, &machinePwrPolicy, sizeof(machinePwrPolicy));
635 
637 
638  return TRUE;
639 }
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
HANDLE PPRegSemaphore
Definition: powrprof.c:56
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static BOOLEAN POWRPROF_GetUserPowerPolicy(LPWSTR szNum, PUSER_POWER_POLICY puserPwrPolicy, DWORD cchName, LPWSTR szName, DWORD cchDesc, LPWSTR szDesc)
Definition: powrprof.c:128
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
static BOOLEAN POWRPROF_GetMachinePowerPolicy(LPWSTR szNum, PMACHINE_POWER_POLICY pmachinePwrPolicy)
Definition: powrprof.c:185

Referenced by CreateEnergyList(), GetCurrentPowerPolicies(), SetActivePwrScheme(), and test_ReadPwrScheme().

◆ SetActivePwrScheme()

BOOLEAN WINAPI SetActivePwrScheme ( UINT  ,
PGLOBAL_POWER_POLICY  ,
PPOWER_POLICY   
)

Definition at line 642 of file powrprof.c.

645 {
646  POWER_POLICY tmp;
647  HKEY hKey;
648  WCHAR Buf[16];
649 
650  if (!ReadPwrScheme(uiID, &tmp))
651  return FALSE;
652 
654  return FALSE;
655 
656  swprintf(Buf, L"%i", uiID);
657 
658  if (RegSetValueExW(hKey, szCurrentPowerPolicies, 0, REG_SZ, (PBYTE)Buf, strlenW(Buf)*sizeof(WCHAR)) != ERROR_SUCCESS)
659  {
660  RegCloseKey(hKey);
661  return FALSE;
662  }
663  RegCloseKey(hKey);
664 
665  if (lpGlobalPowerPolicy != NULL || lpPowerPolicy != NULL)
666  {
667  if (!ValidatePowerPolicies(lpGlobalPowerPolicy, lpPowerPolicy))
668  return FALSE;
669 
670  if (lpGlobalPowerPolicy != NULL && !WriteGlobalPwrPolicy(lpGlobalPowerPolicy))
671  return FALSE;
672 
673  if (lpPowerPolicy != NULL && !WritePwrPolicy(&uiID,lpPowerPolicy))
674  return FALSE;
675  }
676 
677  return TRUE;
678 }
BOOLEAN WINAPI WritePwrPolicy(PUINT puiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:1068
#define TRUE
Definition: types.h:120
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
BOOLEAN WINAPI ReadPwrScheme(UINT uiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:610
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR szCurrentPowerPolicies[]
Definition: powrprof.c:42
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN WINAPI ValidatePowerPolicies(PGLOBAL_POWER_POLICY pGPP, PPOWER_POLICY pPP)
Definition: powrprof.c:851
#define RegOpenKeyEx
Definition: winreg.h:520
BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:690
static const WCHAR szUserPowerConfigSubKey[]
Definition: powrprof.c:40
BYTE * PBYTE
Definition: pedump.c:66
#define REG_SZ
Definition: layer.c:22

Referenced by Pos_SaveData(), ShowPowerSchemesPopupMenu(), test_GetCurrentPowerPolicies(), and test_GetSetActivePwrScheme().

◆ SetSuspendState()

BOOLEAN WINAPI SetSuspendState ( BOOLEAN  ,
BOOLEAN  ,
BOOLEAN   
)

Definition at line 681 of file powrprof.c.

684 {
685  FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
686  return TRUE;
687 }
#define TRUE
Definition: types.h:120
#define FIXME(fmt,...)
Definition: debug.h:110

Referenced by ExitWindowsDialog(), and wmain().

◆ ValidatePowerPolicies()

BOOLEAN WINAPI ValidatePowerPolicies ( PGLOBAL_POWER_POLICY  ,
PPOWER_POLICY   
)

Definition at line 851 of file powrprof.c.

852 {
853  SYSTEM_POWER_CAPABILITIES PowerCaps;
854  NTSTATUS ret;
855  BOOLEAN old;
856 
858  ret = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
859  if (ret != STATUS_SUCCESS)
860  {
862  return FALSE;
863  }
864 
865  if (pGPP)
866  {
867  if (pGPP->user.Revision != 1 || pGPP->mach.Revision != 1)
868  {
870  return FALSE;
871  }
872  if (pGPP->mach.LidOpenWakeAc == PowerSystemUnspecified)
873  {
875  return FALSE;
876  }
877  if ((int)pGPP->mach.LidOpenWakeAc > PowerSystemShutdown)
878  {
880  return FALSE;
881  }
882  if (pGPP->mach.LidOpenWakeDc < PowerSystemWorking)
883  {
885  return FALSE;
886  }
887  if ((int)pGPP->mach.LidOpenWakeDc > PowerSystemShutdown)
888  {
890  return FALSE;
891  }
892  //Lohnegrim: unneeded
893  /*if ((pGPP->mach.LidOpenWakeDc < PowerSystemWorking) || (pGPP->mach.LidOpenWakeDc >= PowerSystemMaximum))
894  {
895  SetLastError(ERROR_GEN_FAILURE);
896  return FALSE;
897  }*/
898  if (!CheckPowerActionPolicy(&pGPP->user.LidCloseAc,PowerCaps))
899  {
900  return FALSE;
901  }
902  if (!CheckPowerActionPolicy(&pGPP->user.LidCloseDc,PowerCaps))
903  {
904  return FALSE;
905  }
906  if (!CheckPowerActionPolicy(&pGPP->user.PowerButtonAc,PowerCaps))
907  {
908  return FALSE;
909  }
910  if (!CheckPowerActionPolicy(&pGPP->user.PowerButtonDc,PowerCaps))
911  {
912  return FALSE;
913  }
914  if (!CheckPowerActionPolicy(&pGPP->user.SleepButtonAc,PowerCaps))
915  {
916  return FALSE;
917  }
918  if (!CheckPowerActionPolicy(&pGPP->user.SleepButtonDc,PowerCaps))
919  {
920  return FALSE;
921  }
922  //Lohnegrim: The BroadcastCapacityResolution presents the Powerlevel in Percent, if invalid set th 100 == FULL
923  if (pGPP->mach.BroadcastCapacityResolution > 100)
924  pGPP->mach.BroadcastCapacityResolution = 100;
925 
926  //Lohnegrim: I have no idea, if they are really needed, or if they are specific for my System, or what they mean, so I removed them
927  //pGPP->user.DischargePolicy[1].PowerPolicy.EventCode = pGPP->user.DischargePolicy[1].PowerPolicy.EventCode | 0x010000;
928  //pGPP->user.DischargePolicy[2].PowerPolicy.EventCode = pGPP->user.DischargePolicy[2].PowerPolicy.EventCode | 0x020000;
929  //pGPP->user.DischargePolicy[3].PowerPolicy.EventCode = pGPP->user.DischargePolicy[3].PowerPolicy.EventCode | 0x030000;
930 
931  FixSystemPowerState(&pGPP->mach.LidOpenWakeAc,PowerCaps);
932  FixSystemPowerState(&pGPP->mach.LidOpenWakeDc,PowerCaps);
933 
934  }
935 
936  if (pPP)
937  {
938  if (pPP->user.Revision != 1 || pPP->mach.Revision != 1)
939  {
941  return FALSE;
942  }
943 
944  //Lohnegrim: unneeded
945  //if (pPP->mach.MinSleepAc < PowerSystemWorking)
946  //{
947  // SetLastError(ERROR_GEN_FAILURE);
948  // return FALSE;
949  //}
950  if ((int)pPP->mach.MinSleepAc >= PowerSystemShutdown)
951  {
953  return FALSE;
954  }
955  //Lohnegrim: unneeded
956  //if (pPP->mach.MinSleepDc < PowerSystemWorking)
957  //{
958  // SetLastError(ERROR_GEN_FAILURE);
959  // return FALSE;
960  //}
961  if ((int)pPP->mach.MinSleepDc >= PowerSystemShutdown)
962  {
964  return FALSE;
965  }
966  if ((int)pPP->mach.ReducedLatencySleepAc == PowerSystemUnspecified)
967  {
969  return FALSE;
970  }
971  if ((int)pPP->mach.ReducedLatencySleepAc > PowerSystemShutdown)
972  {
974  return FALSE;
975  }
976  if ((int)pPP->mach.ReducedLatencySleepDc < PowerSystemWorking)
977  {
979  return FALSE;
980  }
981  if ((int)pPP->mach.ReducedLatencySleepDc > PowerSystemShutdown)
982  {
984  return FALSE;
985  }
986 
987  if (!CheckPowerActionPolicy(&pPP->mach.OverThrottledAc,PowerCaps))
988  {
989  return FALSE;
990  }
991  if (!CheckPowerActionPolicy(&pPP->mach.OverThrottledDc,PowerCaps))
992  {
993  return FALSE;
994  }
995  if (!CheckPowerActionPolicy(&pPP->user.IdleAc,PowerCaps))
996  {
997  return FALSE;
998  }
999  if (!CheckPowerActionPolicy(&pPP->user.IdleDc,PowerCaps))
1000  {
1001  return FALSE;
1002  }
1003  if (pPP->user.MaxSleepAc < PowerSystemWorking)
1004  {
1006  return FALSE;
1007  }
1008  //Lohnegrim: unneeded
1009  /*if ((int)pPP->user.MaxSleepAc > PowerSystemShutdown)
1010  {
1011  SetLastError(ERROR_GEN_FAILURE);
1012  return FALSE;
1013  }*/
1014  if (pPP->user.MaxSleepDc < PowerSystemWorking)
1015  {
1017  return FALSE;
1018  }
1019  //Lohnegrim: unneeded
1020  /*if ((int)pPP->user.MaxSleepDc >= PowerSystemShutdown)
1021  {
1022  SetLastError(ERROR_GEN_FAILURE);
1023  return FALSE;
1024  }*/
1025  if (PowerCaps.SystemS1)
1026  {
1027  pPP->mach.MinSleepAc=PowerSystemSleeping1;
1028  pPP->mach.MinSleepDc=PowerSystemSleeping1;
1029  }
1030  else if (PowerCaps.SystemS2)
1031  {
1032  pPP->mach.MinSleepAc=PowerSystemSleeping2;
1033  pPP->mach.MinSleepDc=PowerSystemSleeping2;
1034  }
1035  else if (PowerCaps.SystemS3)
1036  {
1037  pPP->mach.MinSleepAc=PowerSystemSleeping3;
1038  pPP->mach.MinSleepDc=PowerSystemSleeping3;
1039  }
1040 
1041  if (PowerCaps.SystemS4)
1042  {
1043  pPP->user.MaxSleepAc=PowerSystemSleeping3;
1044  pPP->user.MaxSleepDc=PowerSystemSleeping3;
1045  }
1046  else if (PowerCaps.SystemS3)
1047  {
1048  pPP->user.MaxSleepAc=PowerSystemSleeping2;
1049  pPP->user.MaxSleepDc=PowerSystemSleeping2;
1050  }
1051  else if (PowerCaps.SystemS1)
1052  {
1053  pPP->user.MaxSleepAc=PowerSystemSleeping1;
1054  pPP->user.MaxSleepDc=PowerSystemSleeping1;
1055  }
1056  //Lohnegrim: I don't know where to get this info from, so I removed it
1057  //pPP->user.OptimizeForPowerAc=TRUE;
1058  //pPP->user.OptimizeForPowerDc=TRUE;
1059 
1060  FixSystemPowerState(&pPP->mach.ReducedLatencySleepAc,PowerCaps);
1061  FixSystemPowerState(&pPP->mach.ReducedLatencySleepDc,PowerCaps);
1062  }
1063 
1065  return TRUE;
1066 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG NTSTATUS
Definition: precomp.h:26
static VOID FixSystemPowerState(PSYSTEM_POWER_STATE Psps, SYSTEM_POWER_CAPABILITIES PowerCaps)
Definition: powrprof.c:830
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define ERROR_REVISION_MISMATCH
Definition: winerror.h:788
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
static BOOLEAN CheckPowerActionPolicy(PPOWER_ACTION_POLICY pPAP, SYSTEM_POWER_CAPABILITIES PowerCaps)
Definition: powrprof.c:793
#define SetLastError(x)
Definition: compat.h:409
int ret
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CreateEnergyList(), EnumPowerSchemeCallback(), SetActivePwrScheme(), test_ValidatePowerPolicies(), test_ValidatePowerPolicies_Next(), and test_ValidatePowerPolicies_Old().

◆ WriteGlobalPwrPolicy()

BOOLEAN WINAPI WriteGlobalPwrPolicy ( PGLOBAL_POWER_POLICY  )

Definition at line 690 of file powrprof.c.

691 {
692  HKEY hKey;
695 
696  gupp = pGlobalPowerPolicy->user;
697  gmpp = pGlobalPowerPolicy->mach;
698 
700  L"Control Panel\\PowerCfg\\GlobalPowerPolicy",
701  0,
702  KEY_WRITE,
703  &hKey) != ERROR_SUCCESS)
704  return FALSE;
705 
706  if (RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (PBYTE)&gupp, sizeof(gupp)) != ERROR_SUCCESS)
707  {
708  RegCloseKey(hKey);
709  return FALSE;
710  }
711 
712  RegCloseKey(hKey);
713 
715  L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy",
716  0,
718  &hKey))
719  return FALSE;
720 
721  if (RegSetValueExW(hKey,szPolicies, 0, REG_BINARY, (PBYTE)&gmpp, sizeof(gmpp)) != ERROR_SUCCESS)
722  {
723  RegCloseKey(hKey);
724  return FALSE;
725  }
726 
727  RegCloseKey(hKey);
728  return TRUE;
729 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
static const WCHAR szPolicies[]
Definition: powrprof.c:44
static const WCHAR L[]
Definition: oid.c:1250
#define RegOpenKeyEx
Definition: winreg.h:520
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
BYTE * PBYTE
Definition: pedump.c:66
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by Adv_SaveData(), and SetActivePwrScheme().

◆ WriteProcessorPwrScheme()

BOOLEAN WINAPI WriteProcessorPwrScheme ( UINT  ,
PMACHINE_PROCESSOR_POWER_POLICY   
)

Definition at line 732 of file powrprof.c.

734 {
735  WCHAR Buf[MAX_PATH];
736  HKEY hKey;
737 
738  swprintf(Buf, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\ProcessorPolicies\\%i", ID);
739 
740  if (RegCreateKey(HKEY_LOCAL_MACHINE, Buf, &hKey) != ERROR_SUCCESS)
741  return FALSE;
742 
743  RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (PBYTE)pMachineProcessorPowerPolicy, sizeof(MACHINE_PROCESSOR_POWER_POLICY));
744  RegCloseKey(hKey);
745  return TRUE;
746 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
#define RegCreateKey
Definition: winreg.h:500
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
static const WCHAR szPolicies[]
Definition: powrprof.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1250
#define ID
Definition: ruserpass.c:36
BYTE * PBYTE
Definition: pedump.c:66
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

◆ WritePwrScheme()

BOOLEAN WINAPI WritePwrScheme ( PUINT  ,
LPWSTR  ,
LPWSTR  ,
PPOWER_POLICY   
)

Definition at line 766 of file powrprof.c.

770 {
771  WCHAR Buf[MAX_PATH];
772  HKEY hKey;
773 
774  if (*puiID == -1)
775  {
776  g_LastID++;
777  *puiID = g_LastID;
778  SetLastID();
779  }
780 
781  swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%i", *puiID);
782 
783  if (RegCreateKey(HKEY_CURRENT_USER, Buf, &hKey) != ERROR_SUCCESS)
784  return FALSE;
785 
786  RegSetValueExW(hKey, szName, 0, REG_SZ, (PBYTE)lpszName, strlenW(lpszName)*sizeof(WCHAR));
787  RegSetValueExW(hKey, szDescription, 0, REG_SZ, (PBYTE)lpszDescription, strlenW(lpszDescription)*sizeof(WCHAR));
788  RegCloseKey(hKey);
789  return WritePwrPolicy(puiID, pPowerPolicy);
790 }
static const WCHAR szName[]
Definition: powrprof.c:45
BOOLEAN WINAPI WritePwrPolicy(PUINT puiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:1068
UINT g_LastID
Definition: powrprof.c:52
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegCreateKey
Definition: winreg.h:500
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1250
static VOID SetLastID(VOID)
Definition: powrprof.c:749
BYTE * PBYTE
Definition: pedump.c:66
static const WCHAR szDescription[]
Definition: powrprof.c:46
#define REG_SZ
Definition: layer.c:22

Referenced by SavePowerScheme(), and test_WritePwrScheme().