[ADVAPI32]

Patch by milawynsrealm:
* Implemented the beginnings of InitiateShutdownA/W (nothing works yet, and it's not exported).
* Running InitiateSystemShutdownA/W invokes InitiateSystemShutdownExA/W while
using "Other (Planned)" as the reason code.
        - The "Other (Planned)" reason code seemed to be the best default
option so far. 
        Let me know if you feel otherwise.
* Added the shutdown flags that are used for InitiateShutdownA/W inside of
winreg.h.
* Include the reason.h header inside the winreg.h header so that the reason
codes can be
properly called. This conforms to the VC2010 method of adding this support.
* Added the declarations for InitiateSystemShutdownExA/W and InitiateShutdownA/W inside of winreg.h.
* In winuser.h, change the definitions for EWX_* to conform to MSDN
documentation
        -
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376868%28v=vs.85%29.aspx
* Added definition support for EWX_HYBRID_SHUTDOWN which is found in Windows 8.
* Calling InitiateSystemShutdownExA will convert strings to UNICODE and send it
over to InitiateSystemShutdownExW. The same is also for InitiateShutdownA.

See issue #7245 for more details.

svn path=/trunk/; revision=57089
This commit is contained in:
Aleksey Bragin 2012-08-16 22:14:49 +00:00
parent a4768e7acd
commit 97ce06cdeb
3 changed files with 182 additions and 64 deletions

View file

@ -55,11 +55,10 @@ AbortSystemShutdownA(LPCSTR lpMachineName)
return rv; return rv;
} }
/********************************************************************** /**********************************************************************
* InitiateSystemShutdownW * InitiateSystemShutdownW
* *
* @unimplemented * @implemented
*/ */
BOOL WINAPI BOOL WINAPI
InitiateSystemShutdownW(LPWSTR lpMachineName, InitiateSystemShutdownW(LPWSTR lpMachineName,
@ -67,6 +66,52 @@ InitiateSystemShutdownW(LPWSTR lpMachineName,
DWORD dwTimeout, DWORD dwTimeout,
BOOL bForceAppsClosed, BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown) BOOL bRebootAfterShutdown)
{
return InitiateSystemShutdownExW(lpMachineName,
lpMessage,
dwTimeout,
bForceAppsClosed,
bRebootAfterShutdown,
SHTDN_REASON_MAJOR_OTHER |
SHTDN_REASON_MINOR_OTHER |
SHTDN_REASON_FLAG_PLANNED);
}
/**********************************************************************
* InitiateSystemShutdownA
*
* @implemented
*/
BOOL
WINAPI
InitiateSystemShutdownA(LPSTR lpMachineName,
LPSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown)
{
return InitiateSystemShutdownExA(lpMachineName,
lpMessage,
dwTimeout,
bForceAppsClosed,
bRebootAfterShutdown,
SHTDN_REASON_MAJOR_OTHER |
SHTDN_REASON_MINOR_OTHER |
SHTDN_REASON_FLAG_PLANNED);
}
/******************************************************************************
* InitiateSystemShutdownExW [ADVAPI32.@]
*
* @unimplemented
*/
BOOL WINAPI
InitiateSystemShutdownExW(LPWSTR lpMachineName,
LPWSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown,
DWORD dwReason)
{ {
SHUTDOWN_ACTION Action = ShutdownNoReboot; SHUTDOWN_ACTION Action = ShutdownNoReboot;
NTSTATUS Status; NTSTATUS Status;
@ -87,24 +132,21 @@ InitiateSystemShutdownW(LPWSTR lpMachineName,
return FALSE; return FALSE;
} }
/******************************************************************************
/********************************************************************** * InitiateSystemShutdownExA [ADVAPI32.@]
* InitiateSystemShutdownA
* *
* @unimplemented * see InitiateSystemShutdownExW
*/ */
BOOL BOOL WINAPI
WINAPI InitiateSystemShutdownExA(LPSTR lpMachineName,
InitiateSystemShutdownA(LPSTR lpMachineName,
LPSTR lpMessage, LPSTR lpMessage,
DWORD dwTimeout, DWORD dwTimeout,
BOOL bForceAppsClosed, BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown) BOOL bRebootAfterShutdown,
DWORD dwReason)
{ {
ANSI_STRING MachineNameA; ANSI_STRING MachineNameA, MessageA;
ANSI_STRING MessageA; UNICODE_STRING MachineNameW, MessageW;
UNICODE_STRING MachineNameW;
UNICODE_STRING MessageW;
NTSTATUS Status; NTSTATUS Status;
INT LastError; INT LastError;
BOOL rv; BOOL rv;
@ -118,6 +160,9 @@ InitiateSystemShutdownA(LPSTR lpMachineName,
Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
if (STATUS_SUCCESS != Status) if (STATUS_SUCCESS != Status)
{ {
if(MachineNameW.Buffer)
RtlFreeUnicodeString(&MachineNameW);
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
return FALSE; return FALSE;
} }
@ -129,63 +174,110 @@ InitiateSystemShutdownA(LPSTR lpMachineName,
Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE); Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
if (STATUS_SUCCESS != Status) if (STATUS_SUCCESS != Status)
{ {
if (MachineNameW.Buffer) if (MessageW.Buffer)
{ RtlFreeUnicodeString(&MessageW);
RtlFreeUnicodeString(&MachineNameW);
}
SetLastError(RtlNtStatusToDosError(Status)); SetLastError(RtlNtStatusToDosError(Status));
return FALSE; return FALSE;
} }
} }
rv = InitiateSystemShutdownW(MachineNameW.Buffer, rv = InitiateSystemShutdownExW(MachineNameW.Buffer,
MessageW.Buffer, MessageW.Buffer,
dwTimeout, dwTimeout,
bForceAppsClosed, bForceAppsClosed,
bRebootAfterShutdown); bRebootAfterShutdown,
dwReason);
LastError = GetLastError(); LastError = GetLastError();
if (lpMachineName) if (lpMachineName)
{
RtlFreeUnicodeString(&MachineNameW); RtlFreeUnicodeString(&MachineNameW);
}
if (lpMessage) if (lpMessage)
{
RtlFreeUnicodeString(&MessageW); RtlFreeUnicodeString(&MessageW);
}
SetLastError(LastError); SetLastError(LastError);
return rv; return rv;
} }
/****************************************************************************** /******************************************************************************
* InitiateSystemShutdownExW [ADVAPI32.@] * InitiateShutdownW [ADVAPI32.@]
* *
* see InitiateSystemShutdownExA * @unimplamented
*/ */
BOOL WINAPI DWORD WINAPI
InitiateSystemShutdownExW(LPWSTR lpMachineName, InitiateShutdownW(LPWSTR lpMachineName,
LPWSTR lpMessage, LPWSTR lpMessage,
DWORD dwTimeout, DWORD dwGracePeriod,
BOOL bForceAppsClosed, DWORD dwShutdownFlags,
BOOL bRebootAfterShutdown,
DWORD dwReason) DWORD dwReason)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return TRUE; return ERROR_SUCCESS;
} }
BOOL WINAPI /******************************************************************************
InitiateSystemShutdownExA(LPSTR lpMachineName, * InitiateShutdownA [ADVAPI32.@]
*
* @unimplamented
*/
DWORD WINAPI
InitiateShutdownA(LPSTR lpMachineName,
LPSTR lpMessage, LPSTR lpMessage,
DWORD dwTimeout, DWORD dwGracePeriod,
BOOL bForceAppsClosed, DWORD dwShutdownFlags,
BOOL bRebootAfterShutdown,
DWORD dwReason) DWORD dwReason)
{ {
UNIMPLEMENTED; ANSI_STRING MachineNameA, MessageA;
return TRUE; UNICODE_STRING MachineNameW, MessageW;
NTSTATUS Status;
INT LastError;
DWORD rv;
MachineNameW.Buffer = NULL;
MessageW.Buffer = NULL;
if (lpMachineName)
{
RtlInitAnsiString(&MachineNameA, lpMachineName);
Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
if (STATUS_SUCCESS != Status)
{
if(MachineNameW.Buffer)
RtlFreeUnicodeString(&MachineNameW);
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
}
if (lpMessage)
{
RtlInitAnsiString(&MessageA, lpMessage);
Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
if (STATUS_SUCCESS != Status)
{
if (MessageW.Buffer)
RtlFreeUnicodeString(&MessageW);
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
}
rv = InitiateShutdownW(MachineNameW.Buffer,
MessageW.Buffer,
dwGracePeriod,
dwShutdownFlags,
dwReason);
LastError = GetLastError();
if (lpMachineName)
RtlFreeUnicodeString(&MachineNameW);
if (lpMessage)
RtlFreeUnicodeString(&MessageW);
SetLastError(LastError);
return rv;
} }
/* EOF */ /* EOF */

View file

@ -1,9 +1,12 @@
#ifndef _WINREG_ #ifndef _WINREG_H
#define _WINREG_ #define _WINREG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <reason.h>
#define HKEY_CLASSES_ROOT ((HKEY)0x80000000) #define HKEY_CLASSES_ROOT ((HKEY)0x80000000)
#define HKEY_CURRENT_USER ((HKEY)0x80000001) #define HKEY_CURRENT_USER ((HKEY)0x80000001)
#define HKEY_LOCAL_MACHINE ((HKEY)0x80000002) #define HKEY_LOCAL_MACHINE ((HKEY)0x80000002)
@ -34,6 +37,16 @@ extern "C" {
#define REG_NOTIFY_CHANGE_LAST_SET 4 #define REG_NOTIFY_CHANGE_LAST_SET 4
#define REG_NOTIFY_CHANGE_SECURITY 8 #define REG_NOTIFY_CHANGE_SECURITY 8
/* Shutdown flags for InitiateShutdownA/W */
#define SHUTDOWN_FORCE_OTHERS 0x00000001
#define SHUTDOWN_FORCE_SELF 0x00000002
#define SHUTDOWN_GRACE_OVERRIDE 0x00000020
#define SHUTDOWN_INSTALL_UPDATES 0x00000040
#define SHUTDOWN_NOREBOOT 0x00000010
#define SHUTDOWN_POWEROFF 0x00000008
#define SHUTDOWN_RESTART 0x00000004
#define SHUTDOWN_RESTARTAPPS 0x00000080
#define RRF_RT_REG_NONE (1 << 0) #define RRF_RT_REG_NONE (1 << 0)
#define RRF_RT_REG_SZ (1 << 1) #define RRF_RT_REG_SZ (1 << 1)
#define RRF_RT_REG_EXPAND_SZ (1 << 2) #define RRF_RT_REG_EXPAND_SZ (1 << 2)
@ -64,8 +77,14 @@ typedef struct value_entW {
} VALENTW,*PVALENTW; } VALENTW,*PVALENTW;
BOOL WINAPI AbortSystemShutdownA(LPCSTR); BOOL WINAPI AbortSystemShutdownA(LPCSTR);
BOOL WINAPI AbortSystemShutdownW(LPCWSTR); BOOL WINAPI AbortSystemShutdownW(LPCWSTR);
#if (_WIN32_WINNT >= 0x0600)
DWORD WINAPI InitiateShutdownA(LPSTR, LPSTR, DWORD, DWORD, DWORD);
DWORD WINAPI InitiateShutdownW(LPWSTR, LPWSTR, DWORD, DWORD, DWORD);
#endif
BOOL WINAPI InitiateSystemShutdownA(LPSTR,LPSTR,DWORD,BOOL,BOOL); BOOL WINAPI InitiateSystemShutdownA(LPSTR,LPSTR,DWORD,BOOL,BOOL);
BOOL WINAPI InitiateSystemShutdownW(LPWSTR,LPWSTR,DWORD,BOOL,BOOL); BOOL WINAPI InitiateSystemShutdownW(LPWSTR,LPWSTR,DWORD,BOOL,BOOL);
BOOL WINAPI InitiateSystemShutdownExA(LPSTR,LPSTR,DWORD,BOOL,BOOL,DWORD);
BOOL WINAPI InitiateSystemShutdownExW(LPWSTR,LPWSTR,DWORD,BOOL,BOOL,DWORD);
LONG WINAPI RegCloseKey(HKEY); LONG WINAPI RegCloseKey(HKEY);
LONG WINAPI RegConnectRegistryA(LPCSTR,HKEY,PHKEY); LONG WINAPI RegConnectRegistryA(LPCSTR,HKEY,PHKEY);
LONG WINAPI RegConnectRegistryW(LPCWSTR,HKEY,PHKEY); LONG WINAPI RegConnectRegistryW(LPCWSTR,HKEY,PHKEY);
@ -158,8 +177,10 @@ LONG WINAPI RegUnLoadKeyW(HKEY,LPCWSTR);
typedef VALENTW VALENT,*PVALENT; typedef VALENTW VALENT,*PVALENT;
#define AbortSystemShutdown AbortSystemShutdownW #define AbortSystemShutdown AbortSystemShutdownW
#define InitiateSystemShutdown InitiateSystemShutdownW #define InitiateSystemShutdown InitiateSystemShutdownW
#define InitiateSystemShutdownEx InitiateSystemShutdownExW
#define RegConnectRegistry RegConnectRegistryW #define RegConnectRegistry RegConnectRegistryW
#if (_WIN32_WINNT >= 0x0600) #if (_WIN32_WINNT >= 0x0600)
#define InitiateShutdown InitiateShutdownW
#define RegCopyTree RegCopyTreeW #define RegCopyTree RegCopyTreeW
#endif #endif
#define RegCreateKey RegCreateKeyW #define RegCreateKey RegCreateKeyW
@ -201,8 +222,10 @@ typedef VALENTW VALENT,*PVALENT;
typedef VALENTA VALENT,*PVALENT; typedef VALENTA VALENT,*PVALENT;
#define AbortSystemShutdown AbortSystemShutdownA #define AbortSystemShutdown AbortSystemShutdownA
#define InitiateSystemShutdown InitiateSystemShutdownA #define InitiateSystemShutdown InitiateSystemShutdownA
#define InitiateSystemShutdownEx InitiateSystemShutdownExA
#define RegConnectRegistry RegConnectRegistryA #define RegConnectRegistry RegConnectRegistryA
#if (_WIN32_WINNT >= 0x0600) #if (_WIN32_WINNT >= 0x0600)
#define InitiateShutdown InitiateShutdownA
#define RegCopyTree RegCopyTreeA #define RegCopyTree RegCopyTreeA
#endif #endif
#define RegCreateKey RegCreateKeyA #define RegCreateKey RegCreateKeyA

View file

@ -613,13 +613,16 @@ extern "C" {
#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2 #define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2
#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3 #define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3
#endif #endif
#define EWX_FORCE 4 #define EWX_FORCE 0x00000004
#define EWX_LOGOFF 0 #define EWX_LOGOFF 0
#define EWX_POWEROFF 8 #define EWX_POWEROFF 0x00000008
#define EWX_REBOOT 2 #define EWX_REBOOT 0x00000002
#define EWX_SHUTDOWN 1 #define EWX_SHUTDOWN 0x00000001
#if (_WIN32_WINNT >= 0x0500) #if (_WIN32_WINNT >= 0x0500)
#define EWX_FORCEIFHUNG 16 #define EWX_FORCEIFHUNG 0x00000010
#endif
#if (_WIN32_WINNT > 0x06010000)
#define EWX_HYBRID_SHUTDOWN 0x00400000
#endif #endif
#define CS_BYTEALIGNCLIENT 4096 #define CS_BYTEALIGNCLIENT 4096
#define CS_BYTEALIGNWINDOW 8192 #define CS_BYTEALIGNWINDOW 8192