Below is a small example, which can get the username and main folder of the Windows2000, the WindowsXP system, and the code COPY can run.
Good luck;)
Import java.util. *; import java.io. *;
Public class currentuser {public currentuser () {process p = null; Properties envvars = new profment (); runtime r = runtime.Getruntime (); try {p = r.exec ("cmd.exe / c set user"); BufferedReader Br = New BufferedReader (p.GetInputStream ()))); string line; // The first line is the machine name; the second line is the user name that is currently logged in, the third is the main folder of the current login user. While ((line = br.readline ())! = null) {Int idx = line.indexof ('='); string key = line.substring (0, idx); string value = line.substring (IDX 1 ); Envvars.SetProperty (key, value); system.out.println (key "=" value);}} catch (exception e) {E.PrintStackTrace ();}} public static void main (String [] ARGS) {currentuser currentuser1 = new currentuser ();}}