如何通过Windows API关闭pc? [英] How to turn off pc via windows API?
问题描述
我从不编程一个winapi,所以我有一个小问题。
我需要关闭我的电脑从我的应用程序。 p>
我发现这个例子链接文本,然后我发现这个例子如何更改权限链接文本
但我有问题如何获取该参数HANDLE hToken //访问令牌句柄
我想我需要使它在下一个顺序获得参数
OpenProcessToken LookupPrivilegeValue AdjustTokenPrivileges
,但有很多参数,我不知道该怎么做。
也许你有一些例子我如何得到HANDLE hToken参数来使这项工作。
我已经看到以下帖子链接文字
非常感谢您。
非常适合对Daniel的回答的评论,所以我会把它放在这里。
现在看起来你的主要问题是,你的进程没有运行
ExitWindowsEx 包含此行:
要关闭或重新启动系统,
调用进程必须使用
AdjustTokenPrivileges
函数到
启用SE_SHUTDOWN_NAME
特权。
有关详细信息,请参阅使用$ b运行$ b特别优惠。
他们还有一些示例代码。在捏,你可以复制。
I never programmed a winapi so i have a little problem here .
I need turn off my pc from my application .
I found this example link text then i found this example how to change privileges link text
But i have problem how to get that parameter HANDLE hToken // access token handle
I think i need to make it in the next order to get the parameter OpenProcessToken LookupPrivilegeValue AdjustTokenPrivileges but there are a lot parameters that i have no idea what to do with them .
maybe you have jere some example how i get that HANDLE hToken parameter to make that work .
By the way I already saw the following post link text
Thanks a lot all you .
This is a bit much for the comments on Daniel's answer, so I'll put it here.
It looks like your main issue at this point is that your process isn't running with the priveleges required to perform a system shutdown.
The docs for ExitWindowsEx contain this line:
To shut down or restart the system, the calling process must use the
AdjustTokenPrivileges
function to enable theSE_SHUTDOWN_NAME
privilege. For more information, see Running with Special Privileges.
They also have some example code. In a pinch, you can just copy that.
这篇关于如何通过Windows API关闭pc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!