|
void __fastcall TFormMain::Timer1Timer(TObject *Sender) // 타이머의 타이머값은 적절히 셋팅을...
{
TDateTime Time1, Time2;
Word h1, m1, s1, ms1;
Word h2, m2, s2, ms2;
Time1 = tShutDownTime;
Time2 = Now();
DecodeTime(Time1, h1, m1, s1, ms1);
DecodeTime(Time2, h2, m2, s2, ms2);
if(h1 == h2 && m1 == m2)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, "SeShutdownPrivilege", &luid);
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, false, &tp, 0, NULL, NULL);
ExitWindowsEx(EWX_SHUTDOWN, 0);
}
}
//---------------------------------------------------------------------------
EWX_FORCE
Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_LOGOFF
Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF
Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_REBOOT
Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_SHUTDOWN
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
즐코딩요~~
상우s 님이 쓰신 글 :
: 컴퓨터 에서 시작 시간 알아내는 법하고
:
: 정해진 시간이 됏을 때 윈도우 종료하는 방법좀 자세히 알려주세요
:
: 빠른답변 주시면 감사하겠습니다.
|