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.


My comp is using WinME, but I think I'll scrap the auto logon

Posted by Hiran on November 18, 2001 at 6:17 PM

Matt, I'd appreciate it if you could send me the C++ code for the DLL and the utility that will terminate all non-essential programs. The reason I ask for both is that I would like to try my hand at some JNI, but in case I seem to be really stuck I can then call your utility. Also, just out of curiosity, how do you get the computer to restart. I know a way (using BASIC) to bring up the dialog box that gives the choices of shutting down, restarting, etc. (the same box that comes up if you go to
Start->Shut Down), but I don't know how to actually "force" the computer to shut down or restart. My email address is Thnx.

As an added note: Does anyone know how works exactly? Cause I'm reading from a file (using BufferedReader and FileReader) which is formatted as such: the first line contains a number, the second line some text, the third line some more text and repeat. When I'm reading the file, I use the read() and readLine() methods to read each section (composed of three lines). But for some reason, the read() method seems to skip the first line (containin the int) and reads the first character of the second line and returns a number associated with it (it doesn't seem to be the ASCII equivalent, so it might be the Unicode equivalent). Anyway, here's my simplified code:


public class ReadFile {
BufferedReader fileIn;

public ReadFile(String file) {
try {
fileIn = new BufferedReader(new FileReader(file));
} catch(FileNotFoundException e) {

public void reading() throws IOException {
int line1;
String line2;
String line3;
while(!(fileIn.readLine().equals(""))) {
line1 =;
line2 = fileIn.readLine();
line3 = fileIn.readLine();
System.out.println(line1 + ":-" + line2 + ":-" + line3); //the :- is just a seperator character so that I can distinguish the different lines
try {
Thread.currentThread.sleep(20 * 1000);
} catch(InterruptedException e) {

public static void main(String[] args) {
ReadFile test1 = new ReadFile(test1.txt);
try {
} catch(IOException e) {

If the contents of test1.txt were:


then, the output would be


but, if the contents were:


then, the output would be


whereas if the contents were:


then the output would be:



> 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