Hello,
I wrote a little utility to search for a specific string in the Application Event log in windows 2000 but it is causing me grief.
The app basically takes a host name as a parameter then it is supposed to parse out a username from a text file: AppEvent.evt.
If I delete a single character from the end of the event log it works. But nothing is returned if I point it to an unedited log.
I think this is probably a very simple thing to maybe check for a specific eof char or maybe change the type of stringhandler or something but I'm just not sure.
Anyway, here is the not so optimized code:
import java.io.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringWriter;
import java.io.FilterOutputStream;
import java.io.PrintStream;
public class ProxyHost {
public static void main(String[] args) throws IOException {
if(args.length > 0) {
String theFileName = ("\\\\" + args[0] + "\\c$\\winnt\\system32\\config\\AppEvent.Evt" );
System.out.println(theFileName);
try {
File inputFile = new File(theFileName);
FileReader in = new FileReader(inputFile);
BufferedReader buff = new BufferedReader(in);
StringWriter stringWrite = new StringWriter();
PrintWriter printWrite = new PrintWriter (stringWrite);
String proxyName = null;
boolean eof = false;
int count=0;
int proxyEvent=0;
int proxyNameStart=0;
int proxyNameEnd=0;
int proxyNameLength=0;
while (!eof) {
String line = buff.readLine();
count=count+1;
if (line == null)
eof = true;
else {
/* System.out.println("DEBUG: "+line); */
proxyEvent = line.indexOf("P r o x y H o s t S e r v i c e");
if (proxyEvent != 0 && proxyEvent != -1) {
System.out.println("host service found here: " + line) ;
proxyNameStart = line.indexOf(" a u t h e n t i c a t e d a s B I G - B L U E ",proxyEvent);
proxyNameStart = proxyNameStart+53;
proxyNameEnd = line.indexOf(" ) ",proxyNameStart);
proxyNameLength = proxyNameEnd - proxyNameStart ;
System.out.print("Line: "+count + "offset: "+proxyNameStart+ "Length: "+proxyNameLength +"\n");
stringWrite.write(line, proxyNameStart, proxyNameLength) ;
proxyName = stringWrite.toString();
System.out.print("Name? "+ proxyName);
eof = true;
}
}
}
in.close();
} catch (EOFException e) {
System.err.println("End of stream");
} catch (FileNotFoundException e) {
System.err.println("File Not Found");
}
}
else {
System.out.println("Usage: ProxyHost SERVERNAME") ;
}
}
}
Any help is greatly appreciated,
Aaron
I wrote a little utility to search for a specific string in the Application Event log in windows 2000 but it is causing me grief.
The app basically takes a host name as a parameter then it is supposed to parse out a username from a text file: AppEvent.evt.
If I delete a single character from the end of the event log it works. But nothing is returned if I point it to an unedited log.
I think this is probably a very simple thing to maybe check for a specific eof char or maybe change the type of stringhandler or something but I'm just not sure.
Anyway, here is the not so optimized code:
import java.io.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringWriter;
import java.io.FilterOutputStream;
import java.io.PrintStream;
public class ProxyHost {
public static void main(String[] args) throws IOException {
if(args.length > 0) {
String theFileName = ("\\\\" + args[0] + "\\c$\\winnt\\system32\\config\\AppEvent.Evt" );
System.out.println(theFileName);
try {
File inputFile = new File(theFileName);
FileReader in = new FileReader(inputFile);
BufferedReader buff = new BufferedReader(in);
StringWriter stringWrite = new StringWriter();
PrintWriter printWrite = new PrintWriter (stringWrite);
String proxyName = null;
boolean eof = false;
int count=0;
int proxyEvent=0;
int proxyNameStart=0;
int proxyNameEnd=0;
int proxyNameLength=0;
while (!eof) {
String line = buff.readLine();
count=count+1;
if (line == null)
eof = true;
else {
/* System.out.println("DEBUG: "+line); */
proxyEvent = line.indexOf("P r o x y H o s t S e r v i c e");
if (proxyEvent != 0 && proxyEvent != -1) {
System.out.println("host service found here: " + line) ;
proxyNameStart = line.indexOf(" a u t h e n t i c a t e d a s B I G - B L U E ",proxyEvent);
proxyNameStart = proxyNameStart+53;
proxyNameEnd = line.indexOf(" ) ",proxyNameStart);
proxyNameLength = proxyNameEnd - proxyNameStart ;
System.out.print("Line: "+count + "offset: "+proxyNameStart+ "Length: "+proxyNameLength +"\n");
stringWrite.write(line, proxyNameStart, proxyNameLength) ;
proxyName = stringWrite.toString();
System.out.print("Name? "+ proxyName);
eof = true;
}
}
}
in.close();
} catch (EOFException e) {
System.err.println("End of stream");
} catch (FileNotFoundException e) {
System.err.println("File Not Found");
}
}
else {
System.out.println("Usage: ProxyHost SERVERNAME") ;
}
}
}
Any help is greatly appreciated,
Aaron