Knight_G
asked on
HELP - how to get the system directory?
how to get the system directory (%systemroot%)?
thanks
thanks
ASKER
ok, it works.
but is there any other method that i can retrieve it during runtime?
because i'm will be using exe4j to convert my app to exe and the VM parameter provided by exe4j doesn't support % sign(it will convert to actual '%'). thanks
but is there any other method that i can retrieve it during runtime?
because i'm will be using exe4j to convert my app to exe and the VM parameter provided by exe4j doesn't support % sign(it will convert to actual '%'). thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops, in Windows 95/98
String[] cmd = {"command", "/c", "set"};
String[] cmd = {"command", "/c", "set"};
ASKER
thanx, but it is windows version dependent, my situation is i don't know what version of windows the user currently using, then error will occur if i simply use cmd and command. but i change the code as the following to suit with this situation. thanks for your idea.
Properties prop;
Process process;
try {
String [] cmd1 = {"command", "/c", "set"};
process = Runtime.getRuntime().exec( cmd1);
prop = new Properties();
prop.load( process.getInputStream());
System.out.println("system .root: " + prop.getProperty("SystemRo ot"));
}
catch(Exception e) {
try {
String [] cmd2 = {"cmd", "/c", "set"};
process = Runtime.getRuntime().exec( cmd2);
prop = new Properties();
prop.load( process.getInputStream());
System.out.println("system .root: " + prop.getProperty("SystemRo ot"));
}
catch(Exception ex) {
System.out.println("ex="+e x);
}
}
Properties prop;
Process process;
try {
String [] cmd1 = {"command", "/c", "set"};
process = Runtime.getRuntime().exec(
prop = new Properties();
prop.load( process.getInputStream());
System.out.println("system
}
catch(Exception e) {
try {
String [] cmd2 = {"cmd", "/c", "set"};
process = Runtime.getRuntime().exec(
prop = new Properties();
prop.load( process.getInputStream());
System.out.println("system
}
catch(Exception ex) {
System.out.println("ex="+e
}
}
Here is the way to detect os type.
System.getProperty("os.nam e");
System.getProperty("os.nam
java -Dsystem.root=%SYSTEMROOT%
so in the program,
System.getProperty("system