0

我正在尝试使用以下 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 似乎也没有涵盖这一点。

是否有人必须使用标头或收到类似的错误?我认为它可能对其他头文件有任何依赖关系,但也找不到任何相关信息。

4

0 回答 0