InitiateShutdown is used to reboot the machine if available (patch #247)

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6506 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-06-27 16:30:16 +00:00
parent 2fb86bfa29
commit 45e4a6251b
4 changed files with 34 additions and 6 deletions

View file

@ -10,6 +10,8 @@ Released on ?, 2014
\b Added \R{makensis}{!makensis} command
\b InitiateShutdown is used to reboot the machine if available (\W{http://sf.net/p/nsis/patches/247}{patch #247})
\b Added PPO and SafePPO preprocess-only compiler switches
\b MakeNSIS WM_COPYDATA messages now use the QH_OUTPUTCHARSET encoding with CP_ACP as the default for compatibility with old IDEs.

View file

@ -28,6 +28,25 @@
#include "exec.h"
#include "plugin.h"
#ifndef SHTDN_REASON_FLAG_PLANNED
#define SHTDN_REASON_FLAG_PLANNED 0x80000000
#endif
#ifndef SHTDN_REASON_MAJOR_APPLICATION
#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000
#endif
#ifndef SHTDN_REASON_MINOR_INSTALLATION
#define SHTDN_REASON_MINOR_INSTALLATION 0x0002
#endif
#ifndef SHUTDOWN_RESTART
#define SHUTDOWN_RESTART 0x00000004
#endif
#ifndef SHUTDOWN_FORCE_OTHERS
#define SHUTDOWN_FORCE_OTHERS 0x00000001
#endif
#ifndef SHUTDOWN_GRACE_OVERRIDE
#define SHUTDOWN_GRACE_OVERRIDE 0x00000020
#endif
#if !defined(NSIS_CONFIG_VISIBLE_SUPPORT) && !defined(NSIS_CONFIG_SILENT_SUPPORT)
#error One of NSIS_CONFIG_SILENT_SUPPORT or NSIS_CONFIG_VISIBLE_SUPPORT must be defined.
#endif
@ -317,9 +336,11 @@ end:
#ifdef NSIS_SUPPORT_REBOOT
if (g_exec_flags.reboot_called)
{
const DWORD reason = SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_INSTALLATION;
BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE);
BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID);
BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD);
BOOL (WINAPI *IS)(LPTSTR,LPTSTR,DWORD,DWORD,DWORD);
#ifdef _WIN64
OPT=OpenProcessToken, LPV=LookupPrivilegeValue, ATP=AdjustTokenPrivileges;
#else
@ -340,7 +361,10 @@ end:
}
}
if (!ExitWindowsEx(EWX_REBOOT,0))
IS=myGetProcAddress(MGA_InitiateShutdown);
if (IS && !IS(NULL, NULL, 0, SHUTDOWN_RESTART | SHUTDOWN_FORCE_OTHERS | SHUTDOWN_GRACE_OVERRIDE, reason)
|| !ExitWindowsEx(EWX_REBOOT, reason)
)
ExecuteCallbackFunction(CB_ONREBOOTFAILED);
}
#endif//NSIS_SUPPORT_REBOOT

View file

@ -1031,29 +1031,30 @@ struct MGA_FUNC
const char *func;
};
#ifdef _UNICODE
struct MGA_FUNC MGA_FUNCS[] = {
#ifdef _UNICODE
#ifndef _WIN64
{"KERNEL32", "GetDiskFreeSpaceExW"},
{"KERNEL32", "MoveFileExW"},
{"KERNEL32", "GetUserDefaultUILanguage"},
{"ADVAPI32", "RegDeleteKeyExW"},
{"ADVAPI32", "OpenProcessToken"},
{"ADVAPI32", "LookupPrivilegeValueW"},
{"ADVAPI32", "AdjustTokenPrivileges"},
{"KERNEL32", "GetUserDefaultUILanguage"},
#endif
{"ADVAPI32", "InitiateShutdownW"},
{"SHLWAPI", "SHAutoComplete"},
{"SHFOLDER", "SHGetFolderPathW"}
};
#else
struct MGA_FUNC MGA_FUNCS[] = {
{"KERNEL32", "GetDiskFreeSpaceExA"},
{"KERNEL32", "MoveFileExA"},
{"KERNEL32", "GetUserDefaultUILanguage"},
{"ADVAPI32", "RegDeleteKeyExA"},
{"ADVAPI32", "OpenProcessToken"},
{"ADVAPI32", "LookupPrivilegeValueA"},
{"ADVAPI32", "AdjustTokenPrivileges"},
{"KERNEL32", "GetUserDefaultUILanguage"},
{"ADVAPI32", "InitiateShutdownA"},
{"SHLWAPI", "SHAutoComplete"},
{"SHFOLDER", "SHGetFolderPathA"}
};

View file

@ -120,12 +120,13 @@ enum myGetProcAddressFunctions {
#ifndef _WIN64
MGA_GetDiskFreeSpaceEx,
MGA_MoveFileEx,
MGA_GetUserDefaultUILanguage,
MGA_RegDeleteKeyEx,
MGA_OpenProcessToken,
MGA_LookupPrivilegeValue,
MGA_AdjustTokenPrivileges,
MGA_GetUserDefaultUILanguage,
#endif
MGA_InitiateShutdown,
MGA_SHAutoComplete, // x64 can link to shlwapi directly but as long as MGA_SHGetFolderPath is used we can stick with myGetProcAddress
MGA_SHGetFolderPath, // TODO: This can probably call something else directly on x64
};