shutdown

Shutting down a computer using Java

Is there a way to shutdown a computer using a built-in Java method? ...

How do I get my Java application to shutdown nicely in windows?

I have a Java application which I want to shutdown 'nicely' when the user selects Start->Shutdown. I've tried using JVM shutdown listeners via Runtime.addShutdownHook(...) but this doesn't work as I can't use any UI elements from it. I've also tried using the exit handler on my main application UI window but it has no way to pause or ha...

How to force a reboot instead of shutdown (XP)

I have a Windows XP SP2 virtual machine which can be accessed via VNC. It's also running Deep Freeze so there should be no problem in forcing it to reboot. I am looking for a way to force the operating system to reboot instead of shutting down or completely remove the ability to shut down the machine using software applications (such as ...

How to shutdown the computer from C#

What's the best way to shutdown the computer from a C# program? I've found a few methods that work - I'll post them below - but none of them are very elegant. I'm looking for something that's simpler and natively .net. ...

How do I Shutdown - Restart - Logoff Windows via bat file

I've been using Remote Desktop to get into a workstation but I'm not able to use the shutdown/restart function in the Start menu while doing this. I've put a few really helpful options in the answer below. As I cannot accept this answer, please vote up if you find it appropriate. Note: I wanted to make sure some really good answers ...

Force application to shut down (.net)

Hi I'm looking to force my application to shut down, and return an Exit code. Had a look on MSDN and I can see that in WPF the Application has a Shutdown method which takes an error code as a parameter, but there doesn't appear to be one for System.Windows.Forms.Application. I can see Application.Exit() but not a way to pass back an e...

Ascertaining a shutdown is closing my application

Is it possible in .NET to ascertain whether my application is closing due to Windows being given a shutdown command (as opposed to any old application closing) in order to either write out some temporary cache files or even block the shutdown long enough to prompt for user input? Whilst my current scope involves a Winform app and a wind...

How do I get rid of Java child processes when my Java app exits/crashes?

I launch a child process in Java as follows: final String[] cmd = {"<childProcessName>"}; Process process = Runtime.getRuntime().exec(cmd); It now runs in the background. All good and fine. If my program now crashes (it is still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the pa...

Temporarily prevent linux from shutting down

I have a backup script that runs in the background daily on my linux (Fedora 9) computer. If the computer is shut down while the backup is in progress the backup may be damaged so I would like to write a small script that temporarily disables the ability of the user to reboot or shut the computer down. It is not necessary that the scri...

Windows service shut down

I use VS6 and ATL with CServiceModule to implement a custom windows service. In case of a fatal error service should shut itself down. Since CServiceModule is available via _Module variable in all files I thought of something like this to cause CServiceModule::Run to stop pumping messages and shut itself down PostThreadMessage(_Module.d...

How to programmatically bring a laptop into Sleep mode.

What API or tools can I use to query the capabilities of the system and choose the most appropriate on for putting the PC to Sleep, Hibernate or shutdown mode? Thanks for any pointers. ...

How to stop one of multiple WPF dispatcher?

I have an app with some background threads (actually an in-proc WCF-Service). Each thread runs its own Dispatcher to use some WPF-classes (MediaPlayer-objects to process some audio/video-files; it queues some delegates with BeginInvoke and finally call Dispatcher.Run). When the processing is done, I want to shutdown its dispatcher so tha...

Prompt user to save when closing app

I'm writing what boils down to a document editor. When the application is closing, I need to prompt the user to save changes. This is easy enough. My question is when is it appropriate to not prompt the user, and instead simply discard unsaved data and close. In the FormClosing event, the CloseReason enum includes: None WindowsShutDow...

Win32 API For Shutting Down Another Process Elegantly?

I'm looking for a way to shutdown a windows app from another. Is there a way to do this? Ideally I'd like something that basically mimics an ALT-F4, or pressing the 'X' in the top right corner or some such. Alternatively, is there an application out there that does this already? tskill is a bit too harsh for what I have in mind. ...

How to simulate windows shutdown while debugging?

I have an issue with my application when windows shuts down - my app isn't exiting nicely, resulting in the End Task window being displayed. How can I use the debugger to see what's going on? e.g. is there a way to send the windows shutdown message(s) to my application so it thinks windows is shutting down, so i can see exactly how it b...

Why does my application not close on logoff/shutdown (c#/.net winforms)?

My winforms app isn't shutting down nicely when I log off/shutdown. I have a main form, whose Closing event is fired correctly, but there must be something else keeping my application around. If I check Application.OpenForms there's just my one main form. The tricky bit, and where the problem probably lies, is that my application uses S...

Possible to abort shutdown on Linux?

I'm familiar with and use shutdown in Linux, and typically just do > shutdown -h now But is there a way to stop shutdown from happening, say if I aim to shutdown 10 minutes from now and then in 5 minutes time I discover I really don't want to shut down? ...

What's the best way to shut down a .Net winforms application and delete the executable

I need to shut down my application and then delete the executable. I am doing it by kicking off a low priority batch job and then immediately shutting down the exe. Is there a better way? ...

How to get shutdown hook to execute on a process launched from Eclipse

Hi all. I have a shutdown hook in my application (created using Runtime.getRuntime().addShutdownHook). However if I launch the application from within Eclipse, when it is shut-down the shutdown hook doesn't execute. I think this is because Eclipse sends the equivalent of a force-kill signal to the process, which doesn't cause the shut...

How to abort shutdown in Windows (XP|Vista) programatically?

I want to be able to detect and abort OS shutdown from my application, preferably by using the Windows API. I know that it is possible to do this manually using the command shutdown -a In the worst case, I could ShellExecute this, but I was wondering if there was a better way. Also, how do I find out programatically that the OS is abou...