Shutting down a computer using Java
Is there a way to shutdown a computer using a built-in Java method? ...
Is there a way to shutdown a computer using a built-in Java method? ...
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...
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 ...
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. ...
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 ...
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...
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...
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...
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...
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...
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. ...
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...
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...
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. ...
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...
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...
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? ...
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? ...
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...
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...