#include <windows.h>
void main(int argc, char *argv[])
{
// Get the Windows version.
DWORD dwVersion(GetVersion());
BOOL bIsNT(FALSE);
if(dwVersion < 0x80000000) // Windows NT/2000
bIsNT = TRUE;
if(bIsNT) // Win2000
{
static HANDLE hToken;
static TOKEN_PRIVILEGES tp;
static LUID luid;
::OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
}
if(argc < 2)
::ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0); // 关机
else
::ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); // 重启动
}