shut down the pc when finish...
-
Ing.Raiz82 wrote:
"ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);"
the parameter are incorrect. Use a below ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER );
nave
thanks.... but don't work... i don't understand.... i create a simple button and.. void CSmartAdvertiseDlg::OnBnClickedButton1() { ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER ); } but don't work.....ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh thanks giulio
-
Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio
-
U can't directly use this API. To use the API, u'r process should have sufficient privileges. The Privilege required is SE_SHUTDOWN_NAME. Use
OpenProcessToken()
and
AdjustTokenPrivileges()
to get the right privilege.
Come online at:- jubinc@skype
thanks a lot... but i'm a beginner... can you see me an example? sorry... and thanks too...
-
thanks.... but don't work... i don't understand.... i create a simple button and.. void CSmartAdvertiseDlg::OnBnClickedButton1() { ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER ); } but don't work.....ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh thanks giulio
Whats return value of
ExitWindowsEx
WhiteSky
-
Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio
-
thanks a lot... but i'm a beginner... can you see me an example? sorry... and thanks too...
-
thank you so much.. bye... Giulio
-
thank you so much.. bye... Giulio
You're welcome;)
WhiteSky
-
Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio
ok.... This is the code... it work....:) //giulio shutdown pc HANDLE hToken; TOKEN_PRIVILEGES tkp; if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0)) { ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF|EWX_FORCE,0); } } :):):):):):):):) Bye Giulio
-
Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio
ExitWindowsEx Windows NT/2000/XP: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, see Privileges. Windows 95/98/Me: ExitWindowEx does not work from a console application. HANDLE hToken; // handle to process token TOKEN_PRIVILEGES tkp; // pointer to token structure if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { return (FALSE); } LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); Then call ExitWindowsEx function :)
Known is a drop, unknown is an ocean