如何关闭锁定的电脑(vb.net)?
在 vb.net 中关闭电脑很容易:
Process.Start("shutdown", "-s -t 00")
除非用户锁定了电脑,在这种情况下上述操作将失败。
如何在 vb.net 中解决这个问题?如何关闭锁定的电脑?
该程序将在本地运行。
Shutting down a pc in vb.net is easy:
Process.Start("shutdown", "-s -t 00")
unless the user has locked the pc in which case the above fails.
How do I get around this in vb.net? How do I shutdown a locked PC?
The program will be running locally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 System.Management 命名空间比启动外部工具更优雅。以下是 C# 代码示例,应该相当容易转换:
http://www.dreamincode.net/forums/topic/33948-how-to-shut-down-your-computer-in-c%23/
Using the
System.Management
namespace is more elegant than starting an external tool. Here is a code example in C#, which should be fairly easy to convert:http://www.dreamincode.net/forums/topic/33948-how-to-shut-down-your-computer-in-c%23/
查看 CodeProject 上的这篇文章,其中说明了强制远程关闭计算机为您提供如何操作的想法。
Have a look at this article on CodeProject which illustrates forcing a computer to shutdown remotely to give you an idea on how to do it.
对于后代:
Google“Win32Shutdown”以获取可用标志的更多详细信息(上面的 ss)。 5 是在电脑锁定时强制关机,但它比 shutdown /f 更优雅,并且不会在重新启动时导致程序或服务出现任何问题。
For posterity:
Google "Win32Shutdown" for more details of the flags available (ss above). 5 is a forced shutdown for when the pc is locked but it's more graceful than shutdown /f and doesn't appear to cause any problems with programs or services on restart.
我认为您正在寻找“-f”标志来强制关闭。
引用 MS 知识库文章:
当计算机被锁定时,如果您与 -f 选项一起运行 Shutdown.exe 命令,则可以关闭计算机。
I think you're looking for the '-f' flag to force a shutdown.
Quote from a MS KB article:
When the computer is locked, you can shut down the computer, if you run the Shutdown.exe command together with the -f option.
你可以 P/Invoke ExitWindowsEx
有一个 C# 示例在那里,但我相信你可以转换它。
You could P/Invoke ExitWindowsEx
There is an example in C# there, but I'm sure you can convert it.
这将在 00 毫秒内强制关闭。您必须调用每个进程的代码是多余的,请使用上面的代码。只需在顶部执行
System.Imports.IO
即可。This will force a shutdown In 00ms silently. The code you have to invoke each process is redundant, use the code above. Just do a
System.Imports.IO
at the top and you are good to go.