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!
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!
You can use the
ExitWindowsEx
API. From pinvoke.netAnd to use it:
An alternative would be to use WMI (i.e. the
System.Management
namespace); Google brings up variations on this code --Try this:
This starts Windows' inbuilt
shutdown
tool, which can also shut down or logoff a remote or the local machine.Here is the list of full options from ss64.com:
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.