想Restart Computer碰到的问题,知道的一下就搞定了...
查MSDN,ExitWindowsEx ,
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.
调用告诉说没有权限 >>
BOOL AdjustTokenPrivileges(
HANDLE TokenHandle, // handle to token
BOOL DisableAllPrivileges, // disabling option
PTOKEN_PRIVILEGES NewState, // privilege information
DWORD BufferLength, // size of buffer
PTOKEN_PRIVILEGES PreviousState, // original state buffer
PDWORD ReturnLength // required buffer size
); >>
需handle to token >>
BOOL OpenProcessToken(
HANDLE ProcessHandle, // handle to process
DWORD DesiredAccess, // desired access to process
PHANDLE TokenHandle // handle to open access token
);
or
BOOL OpenThreadToken(
HANDLE ThreadHandle, // handle to thread
DWORD DesiredAccess, // access to process
BOOL OpenAsSelf, // process or thread security
PHANDLE TokenHandle // handle to open access token
);
>> handle to thread or handle to process
>> 使用
GetCurrentProcess
GetCurrentThread
OpenProcess
等函数来获取的handle在调用OpenThreadToken or OpenProcessToken时都返回错误
说不存在的1008:试图引用不存在的令牌。
不知道怎么回事,知道的告诉一把,thx
当然,能告诉不如此,怎么就可以enable the SE_SHUTDOWN_NAME privilege更好