如何通过Windows API关闭电脑?
我从未编写过winapi,所以我在这里遇到了一些问题。
我需要从我的应用程序中关闭我的电脑。
我找到了这个示例 链接文本 然后我找到这个示例如何更改权限链接文本
但我有如何获取该参数的问题 HANDLE hToken // 访问令牌句柄
我认为我需要按照下一个顺序来获取参数 OpenProcessToken LookupPrivilegeValue AdjustTokenPrivileges 但有很多参数我不知道如何处理它们。
也许你有一些例子,我如何获取 HANDLE hToken 参数来使其工作。
顺便说一句,我已经看到以下帖子链接文本
非常感谢大家。
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 .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 ShellExecute() 来调用 shutdown.exe
You could use ShellExecute() to call shutdown.exe
对于Daniel的回答的评论有点多,所以我就放在这里。
目前看来您的主要问题是您的进程没有以执行系统关闭所需的权限运行。
ExitWindowsEx 的文档包含以下行:
他们还有一些示例代码。在紧要关头,你可以复制它。
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:
They also have some example code. In a pinch, you can just copy that.
http://msdn.microsoft.com/en-us /library/aa376868(VS.85).aspx
尝试
http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx
Try
InitiateSystemShutdownEx
的一些工作代码:据我所知,相对于
ExitWindowsEx
解决方案的优点是调用进程不需要属于活动用户。Some working code for
InitiateSystemShutdownEx
:So far as I can tell, the advantage to this over the
ExitWindowsEx
solution is that the calling process does not need to belong to the active user.