added wxShutdown (patch 547443)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15383 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
32b5be3d67
commit
f6ba47d997
@ -131,6 +131,7 @@ wxBase:
|
||||
- fixed the bug related to the redrawing on resize introduced in 2.3.2
|
||||
- added static wxFontMapper::Get() accessor (use of wxTheFontMapper is now
|
||||
deprecated)
|
||||
- added wxShutdown() function (Marco Cavallini)
|
||||
|
||||
Unix (Base/GUI):
|
||||
|
||||
|
@ -196,6 +196,7 @@ the corresponding topic.
|
||||
\helpref{wxSetWorkingDirectory}{wxsetworkingdirectory}\\
|
||||
\helpref{wxShell}{wxshell}\\
|
||||
\helpref{wxShowTip}{wxshowtip}\\
|
||||
\helpref{wxShutdown}{wxshutdown}\\
|
||||
\helpref{wxSleep}{wxsleep}\\
|
||||
\helpref{wxSnprintf}{wxsnprintf}\\
|
||||
\helpref{wxSplitPath}{wxsplitfunction}\\
|
||||
@ -595,6 +596,26 @@ See also \helpref{wxExecute}{wxexecute}, \helpref{Exec sample}{sampleexec}.
|
||||
|
||||
<wx/utils.h>
|
||||
|
||||
\membersection{::wxShutdown}\label{wxshutdown}
|
||||
|
||||
\func{bool}{wxShutdown}{\param{wxShutdownFlags}{flags}}
|
||||
|
||||
This function shuts down or reboots the computer depending on the value of the
|
||||
{\it flags}. Please notice that doing this requires the corresponding access
|
||||
rights (superuser under Unix, {\tt SE\_SHUTDOWN} privelege under Windows NT)
|
||||
and that this function is only implemented under Unix and Win32.
|
||||
|
||||
\wxheading{Parameters}
|
||||
|
||||
\docparam{flags}{Either {\tt wxSHUTDOWN\_POWEROFF} or {\tt wxSHUTDOWN\_REBOOT}}
|
||||
|
||||
\wxheading{Returns}
|
||||
|
||||
{\tt TRUE} on success, {\tt FALSE} if an error occured.
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/utils.h>
|
||||
|
||||
\section{Thread functions}\label{threadfunctions}
|
||||
|
||||
|
@ -220,6 +220,15 @@ enum wxKillError
|
||||
wxKILL_ERROR // another, unspecified error
|
||||
};
|
||||
|
||||
enum wxShutdownFlags
|
||||
{
|
||||
wxSHUTDOWN_POWEROFF, // power off the computer
|
||||
wxSHUTDOWN_REBOOT // shutdown and reboot
|
||||
};
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
WXDLLEXPORT bool wxShutdown(wxShutdownFlags wFlags);
|
||||
|
||||
// send the given signal to the process (only NONE and KILL are supported under
|
||||
// Windows, all others mean TERM), return 0 if ok and -1 on error
|
||||
//
|
||||
|
@ -139,6 +139,13 @@ bool wxShell(const wxString& command)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
bool wxShutdown(wxShutdownFlags wFlags)
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
|
||||
long wxGetFreeMemory()
|
||||
{
|
||||
|
@ -139,6 +139,13 @@ bool wxShell(const wxString& command)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
bool wxShutdown(wxShutdownFlags wFlags)
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
|
||||
long wxGetFreeMemory()
|
||||
{
|
||||
|
@ -845,7 +845,7 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else // Win15
|
||||
#else // Win16
|
||||
wxFAIL_MSG( _T("not implemented") );
|
||||
#endif // Win32/Win16
|
||||
|
||||
@ -875,6 +875,66 @@ bool wxShell(const wxString& command)
|
||||
return wxExecute(cmd, TRUE /* sync */) != 0;
|
||||
}
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
bool wxShutdown(wxShutdownFlags wFlags)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
bool bOK = TRUE;
|
||||
|
||||
if ( wxGetOsVersion(NULL, NULL) == wxWINDOWS_NT ) // if is NT or 2K
|
||||
{
|
||||
// Get a token for this process.
|
||||
HANDLE hToken;
|
||||
bOK = ::OpenProcessToken(GetCurrentProcess(),
|
||||
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
|
||||
&hToken) != 0;
|
||||
if ( bOK )
|
||||
{
|
||||
TOKEN_PRIVILEGES tkp;
|
||||
|
||||
// Get the LUID for the shutdown privilege.
|
||||
::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
|
||||
&tkp.Privileges[0].Luid);
|
||||
|
||||
tkp.PrivilegeCount = 1; // one privilege to set
|
||||
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
|
||||
// Get the shutdown privilege for this process.
|
||||
::AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
|
||||
(PTOKEN_PRIVILEGES)NULL, 0);
|
||||
|
||||
// Cannot test the return value of AdjustTokenPrivileges.
|
||||
bOK = ::GetLastError() == ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bOK )
|
||||
{
|
||||
UINT flags = EWX_SHUTDOWN | EWX_FORCE;
|
||||
switch ( wFlags )
|
||||
{
|
||||
case wxSHUTDOWN_POWEROFF:
|
||||
flags |= EWX_POWEROFF;
|
||||
break;
|
||||
|
||||
case wxSHUTDOWN_REBOOT:
|
||||
flags |= EWX_REBOOT;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown wxShutdown() flag") );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bOK = ::ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE | EWX_REBOOT, 0) != 0;
|
||||
}
|
||||
|
||||
return bOK;
|
||||
#else // Win16
|
||||
return FALSE;
|
||||
#endif // Win32/16
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// misc
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -198,6 +198,13 @@ bool wxShell(
|
||||
return (rc != 0);
|
||||
}
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
bool wxShutdown(wxShutdownFlags wFlags)
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
|
||||
long wxGetFreeMemory()
|
||||
{
|
||||
|
@ -290,6 +290,29 @@ bool wxShell(const wxString& command, wxArrayString& output)
|
||||
return wxExecute(wxMakeShellCommand(command), output);
|
||||
}
|
||||
|
||||
// Shutdown or reboot the PC
|
||||
bool wxShutdown(wxShutdownFlags wFlags)
|
||||
{
|
||||
wxChar level;
|
||||
switch ( wFlags )
|
||||
{
|
||||
case wxSHUTDOWN_POWEROFF:
|
||||
level = _T('0');
|
||||
break;
|
||||
|
||||
case wxSHUTDOWN_REBOOT:
|
||||
level = _T('6');
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown wxShutdown() flag") );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return system(wxString::Format(_T("init %c"), level).mb_str()) == 0;
|
||||
}
|
||||
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
void wxHandleProcessTermination(wxEndProcessData *proc_data)
|
||||
|
Loading…
Reference in New Issue
Block a user