The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Restarting the computer w/ a JAVA program

Posted by Matt Gerrans on November 18, 2001 at 4:51 PM

Hi Hiran,

These are things that you cannot really do with Java (you can kind of do it using JNI, but you'll still have to write non-Java code). I have done all them except the auto-logon with C++/Windows API.

If you want, I can send you some utility programs I've written that will reboot windows and that will terminate all "non-essential" processes. You could run these with Runtime.exec(), which is a lot less work than all the JNI stuff and amounts to the same thing, essentially. If you want to do the JNI for practice and experience (it isn't too tough), I can give you some C++ source code to use on the DLL side.

The trick to running a program exclusively on startup is to put it in the RunOnce key in the registry (not the Run); this is because the programs in RunOnce are executed serially, whereas those in Run are all forked "in parallel."

As far as the auto-login, I haven't done that before, but I suspect, it may be possible to set things up so that it boots with no login into a mode where it does your defrag, then reboots again and presents you with your normal login. That is, while doing the defrag, it is not logged on as you, but as some user (eg. "D. Frag") who has no login password.

By the way, is this Windows 9x/Me, NT, 2k, or XP, or... Depending upon the OS, the login trick may be more or less difficult.

- mfg

> Does anyone know if it's possible to restart the machine from a JAVA program? Also, is it possible to bypass the login screen that comes up when the machine starts up? When I say bypass, I mean have a program login as if the user had entered the password? The reason I ask is that I want to create an application that'll restart my machine and login for me and then start the disk defragmenter (or something like that) before any of my programs (like MSN Messenger, etc.) start up and then cause the disk defragmenter to restart constantly. I've set my computer to defragment every day at 5am (since I'm asleep at that time) but the only problem is that if I leave my computer on throughout the night, then all my IM programs are running and cause the defragment program to constanlty restart (the effect being that I wake up and find that the defragmenting hasn't even started yet). I know I could just close all those other programs before I go to bed, but I'm curious now as to whether I can create a program that'll deal with all that. (And I don't want to get into programming to the Windows API to close any programs that are running unless I have to, or unless it's the easiest solution). Thnx in advance!
> Hiran


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us