made the Reboot command first quit and then reboot

- fixed bug #989690
 - the installer now denies reboots while running
 - the Reboot instruction no longer returns or sets the error flag
 - added .onRebootFailed which is called when Reboot fails
 - installer should now always clean-up when rebooting


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3729 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-10-14 13:56:02 +00:00
parent b5cab9b25f
commit 335fd47066
10 changed files with 100 additions and 58 deletions

View file

@ -245,8 +245,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
g_exec_flags.errlvl = -1;
ret = ui_doinstall();
if (g_exec_flags.errlvl != -1)
ret = g_exec_flags.errlvl;
#ifdef NSIS_CONFIG_LOG
#ifndef NSIS_CONFIG_LOG_ODS
@ -257,17 +255,53 @@ end:
CleanUp();
if (m_Err)
{
my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20));
ret = 2;
}
#if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT)
OleUninitialize();
#endif
if (m_Err)
{
my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20));
ExitProcess(2);
return 0;
}
#ifdef NSIS_SUPPORT_REBOOT
if (g_exec_flags.reboot_called)
{
HANDLE h=GetModuleHandle("ADVAPI32.dll");
if (h)
{
BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE);
BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID);
BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD);
OPT=(void*)GetProcAddress(h,"OpenProcessToken");
LPV=(void*)GetProcAddress(h,"LookupPrivilegeValueA");
ATP=(void*)GetProcAddress(h,"AdjustTokenPrivileges");
if (OPT && LPV && ATP)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (OPT(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
LPV(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
ATP(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
}
}
if (!ExitWindowsEx(EWX_REBOOT,0))
ExecuteCallbackFunction(CB_ONREBOOTFAILED);
}
#endif//NSIS_SUPPORT_REBOOT
if (g_exec_flags.errlvl != -1)
ret = g_exec_flags.errlvl;
ExitProcess(ret);
return 0;
}
void NSISCALL CleanUp()

View file

@ -577,7 +577,12 @@ skipPage:
m_curwnd = (HWND)wParam;
goto skipPage;
}
if (uMsg == WM_QUERYENDSESSION || (uMsg == WM_CLOSE && m_page == g_blocks[NB_PAGES].num - 1))
if (uMsg == WM_QUERYENDSESSION)
{
SetWindowLong(hwndDlg, DWL_MSGRESULT, FALSE);
return TRUE;
}
if (uMsg == WM_CLOSE && m_page == g_blocks[NB_PAGES].num - 1)
{
if (!IsWindowEnabled(m_hwndCancel))
{

View file

@ -1056,39 +1056,10 @@ static int NSISCALL ExecuteEntry(entry *entry_)
my_MessageBox(GetNSISStringTT(LANG_INSTCORRUPTED),MB_OK|MB_ICONSTOP|(IDOK<<20));
return EXEC_ERROR;
}
g_exec_flags.exec_error++;
{
HANDLE h=LoadLibrary("ADVAPI32.dll");
if (h)
{
BOOL (WINAPI *OPT)(HANDLE, DWORD,PHANDLE);
BOOL (WINAPI *LPV)(LPCTSTR,LPCTSTR,PLUID);
BOOL (WINAPI *ATP)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD);
OPT=(void*)GetProcAddress(h,"OpenProcessToken");
LPV=(void*)GetProcAddress(h,"LookupPrivilegeValueA");
ATP=(void*)GetProcAddress(h,"AdjustTokenPrivileges");
if (OPT && LPV && ATP)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (OPT(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
LPV(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
ATP(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
}
FreeLibrary(h);
}
if (ExitWindowsEx(EWX_REBOOT,0))
{
g_quit_flag++;
PostQuitMessage(0);
return EXEC_ERROR;
}
}
g_exec_flags.reboot_called++;
// a following EW_QUIT will make sure the installer quits right away
break;
#endif//NSIS_SUPPORT_REBOOT
#ifdef NSIS_SUPPORT_INIFILES

View file

@ -291,14 +291,15 @@ typedef struct
#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
int code_onGUIInit;
int code_onGUIEnd;
#endif
int code_onVerifyInstDir;
#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
int code_onMouseOverSection;
#endif
#endif//NSIS_CONFIG_ENHANCEDUI_SUPPORT
int code_onVerifyInstDir;
#ifdef NSIS_CONFIG_COMPONENTPAGE
int code_onSelChange;
#endif//NSIS_CONFIG_COMPONENTPAGE
#ifdef NSIS_SUPPORT_REBOOT
int code_onRebootFailed;
#endif//NSIS_SUPPORT_REBOOT
#endif//NSIS_SUPPORT_CODECALLBACKS
#ifdef NSIS_CONFIG_COMPONENTPAGE
@ -320,14 +321,15 @@ enum
#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
CB_ONGUIINIT,
CB_ONGUIEND,
#endif
CB_ONVERIFYINSTDIR,
#ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
CB_ONMOUSEOVERSECTION,
#endif
#endif//NSIS_CONFIG_ENHANCEDUI_SUPPORT
CB_ONVERIFYINSTDIR,
#ifdef NSIS_CONFIG_COMPONENTPAGE
CB_ONSELCHANGE
CB_ONSELCHANGE,
#endif//NSIS_CONFIG_COMPONENTPAGE
#ifdef NSIS_SUPPORT_REBOOT
CB_ONREBOOTFAILED
#endif//NSIS_SUPPORT_REBOOT
};
#endif//NSIS_SUPPORT_CODECALLBACKS
@ -459,6 +461,7 @@ typedef struct
int abort;
#ifdef NSIS_SUPPORT_REBOOT
int exec_reboot;
int reboot_called;
#endif
int cur_insttype;
int insttype_changed;