public String getComputerName_Windows() {
Map env = System.getenv();
if (env.containsKey("COMPUTERNAME")) {
return (String) env.get("COMPUTERNAME");
}
return "unknown";
}
Example Demo:
package zexample;
import java.util.Map;
/**
*
* @author http://titodev.blogspot.com/
*/
public class zExample {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Computer name: " + getComputerName_Windows());
}
public static String getComputerName_Windows() {
Map env = System.getenv();
if (env.containsKey("COMPUTERNAME")) {
return (String) env.get("COMPUTERNAME");
}
return "unknown";
}
}