从C#/ WPF应用程序重新启动机器

编程入门 行业动态 更新时间:2024-10-28 03:29:50
本文介绍了从C#/ WPF应用程序重新启动机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想有一个按钮,在我的WPF应用程序,重新启动计算机。这个程序是始终在Vista上运行。

I want to have a button in my WPF app that restarts the machine. This app is always running on Vista.

这是一个快速搜索并没有变成任何东西的事实,让我觉得这可能是难度比我想这是......什么想法?谢谢!

The fact that a quick search hasn't turned anything up makes me think this might be harder than I wish it was... any ideas? Thanks!

推荐答案

试试这个:

System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");

这将启动Windows的内置关闭工具,也可以关闭或注销远程或本地计算机。

This starts Windows' inbuilt shutdown tool, which can also shut down or logoff a remote or the local machine.

下面是充分的选择从 ss64 列表:

Here is the list of full options from ss64:

Syntax SHUTDOWN [logoff_option] [/m \\Computer] [options] logoff_option: /i Display the GUI (must be the first option) /l Log off. This cannot be used with /m or /d option /s Shutdown /r Shutdown and Restart /a Abort a system shutdown. (only during the time-out period) /p Turn off the local computer with no time-out or warning (only with /d) /h Hibernate the local computer (only with /f ) /e Document the reason for an unexpected shutdown of a computer Options: /m \\Computer : A remote computer to shutdown. /t:xxx : Time until system shutdown in seconds. The valid range is xxx=0-600 seconds. [default=30] /c "Msg" : An optional shutdown message [Max 127 chars] /f : Force running applications to close. This will not prompt for File-Save in any open applications. so will result in a loss of all unsaved data!!! /d u:xx:yy : List a USER reason code for the shutdown. /d P:xx:yy : List a PLANNED reason code for the shutdown. xx Specifies the major reason code (0-255) yy Specifies the minor reason code (0-65536)

您可能会注意到,我已经使用过的命令行参数(使用' - ')的Linux / UNIX的风格标志。在Windows中,约定使用/。这并不重要 - 该程序不关心

You'll probably notice that I have used the Linux/UNIX style of passing command-line arguments (using the '-') sign. On Windows, the convention is using '/'. This doesn't matter - the program doesn't care.

更多推荐

从C#/ WPF应用程序重新启动机器

本文发布于:2023-11-02 13:11:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重新启动   应用程序   机器   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!