我正在尝试使用以下C代码编写程序以在特定时间重新启动计算机:
//A program to reboot the computer
#include <stdio.h>
#include <Windows.h>
#include <Winbase.h>
#include <Winuser.h>
#include <Reason.h>
void myExitWindowsEx (UINT uFlags, DWORD dwReason) {
HANDLE handleToTokenUID;
LUID UUIDShutDownPermission;
TOKEN_PRIVILEGES PrivProperties;
OpenProcessToken (GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &handleToTokenUID);
LookupPrivilegeValue (NULL, "SeShutdownPrivilege", &UUIDShutDownPermission);
PrivProperties.PrivilegeCount = 1;
PrivProperties.Privileges[0].Luid = UUIDShutDownPermission;
PrivProperties.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges (handleToTokenUID, FALSE, &PrivProperties, 0, NULL, NULL);
ExitWindowsEx(uFlags, dwReason);
}
int main (void) {
struct _SYSTEMTIME time;
void myExitWindowsEx (UINT uFlags, DWORD dwReason);
//Now we are calling the function to reboot the computer with appropriate flags
while (1) {
Sleep (59000);
GetSystemTime;
if (time.wHour == 3 && time.wMinute == 0) {
myExitWindowsEx(EWX_REBOOT, SHTDN_REASON_FLAG_PLANNED);
break; }
}
return 0;
}
但是未定义SHTDN_REASON_FLAG_PLANNED
(Windows关闭原因是ExitWindowsEx
所需参数)的错误。原因是编译器无法找到Reason.h
头文件。
谷歌搜索没有返回任何相关结果,MSDN似乎也没有提到这一点。
是否有人必须使用标头或收到类似的错误?我认为它可能有任何依赖于其他头文件,但也找不到任何信息。