How to simulate Windows shutdown for debugging?

There is a tool named Restart Manager (rmtool.exe) in the Microsoft’s Logo Testing Tools for Windows, which can be used to send shutdown and restart messages to a process. Logo testing tools can be downloaded here: http://download.microsoft.com/download/d/2/5/d2522ce4-a441-459d-8302-be8f3321823c/LogoToolsv1.0.msi Then you can simulate shutdown for your process: rmtool.exe -p [PID] -S where [PID] is the process ID. … Read more

Close a WP7 application programmatically? [duplicate]

You can always call an exit by doing this at your landing page use this code on click of your application back button: if (NavigationService.CanGoBack) { while (NavigationService.RemoveBackEntry() != null) { NavigationService.RemoveBackEntry(); } } This will remove back entries from the stack, and you will press a back button it will close the application without … Read more

How do I shutdown, restart, or log off Windows via a bat file?

The most common ways to use the shutdown command are: shutdown -s — Shuts down. shutdown -r — Restarts. shutdown -l — Logs off. shutdown -h — Hibernates. Note: There is a common pitfall wherein users think -h means “help” (which it does for every other command-line program… except shutdown.exe, where it means “hibernate”). They … Read more

Java shutdown hook

The JVM can shutdown in either an orderly or abrupt manner. A shutdown hook runs for an orderly shutdown: when the last normal thread terminates, someone calls System.exit or by other platform specific means (such as typing Ctrl-C). Shutdown hooks will not run for an abrupt shutdown of the JVM. As you are pressing the … Read more

Shutting down a computer

Create your own function to execute an OS command through the command line? For the sake of an example. But know where and why you’d want to use this as others note. public static void main(String arg[]) throws IOException{ Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(“shutdown -s -t 0”); System.exit(0); }

How to shutdown an ExecutorService?

The typical pattern is: executorService.shutdownNow(); executorService.awaitTermination(); When calling shutdownNow, the executor will (generally) try to interrupt the threads that it manages. To make the shutdown graceful, you need to catch the interrupted exception in the threads or check the interrupted status. If you don’t your threads will run forever and your executor will never be … Read more

How do I exit a WPF application programmatically?

To exit your application you can call System.Windows.Application.Current.Shutdown(); As described in the documentation to the Application.Shutdown method you can also modify the shutdown behavior of your application by specifying a ShutdownMode: Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations: When ShutdownMode is set to OnLastWindowClose. When the ShutdownMode is set … Read more