gpt4 book ai didi

c - 在 Winapi 中以编程方式关闭远程机器

转载 作者:太空宇宙 更新时间:2023-11-04 06:24:32 24 4
gpt4 key购买 nike

假设我拥有所有必要的权限,我将如何关闭或重新启动同一 LAN 中的系统。

请看下面的代码

OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, 
&tokenHandle);

LookupPrivilegeValue("Computer name", SE_REMOTE_SHUTDOWN_NAME,
&tokenPrivileges.Privileges[0].Luid);

tokenPrivileges.PrivilegeCount = 1;
tokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(tokenHandle, FALSE, &tokenPrivileges, 0,
0, 0);

switch(action)
{
default:
case constEWXReboot:
case constEWXRestartApps:
if (!InitiateSystemShutdownEx("Computer name","Remote machine shutdown", 10, TRUE, TRUE, SHTDN_REASON_MAJOR_APPLICATION))
{
ErrGen(constErrCannotRestartSystem);
}
break;

我收到错误代码 #53 未找到网络路径。请建议我哪里出错了。

最佳答案

InitiateSystemShutdownEx win API 函数将执行此操作。

Initiates a shutdown and optional restart of the specified computer, and optionally records the reason for the shutdown.

To shut down the local computer, the calling thread must have the SE_SHUTDOWN_NAME privilege. To shut down a remote computer, the calling thread must have the SE_REMOTE_SHUTDOWN_NAME privilege on the remote computer. By default, users can enable the SE_SHUTDOWN_NAME privilege on the computer they are logged onto, and administrators can enable the SE_REMOTE_SHUTDOWN_NAME privilege on remote computers.

关于c - 在 Winapi 中以编程方式关闭远程机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28873762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com