获取本机信息和打开本地程序
package systeminfo;import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*;
/*
* 获取本机的硬件信息
* 打开本机exe程序
*/
public class Systeminfo {
private static void showSystemInfo()
{
List<String> props = new ArrayList<String>();
System.out.println("\n\n--- [ System Info ] ------------------------------------------\n");
props.add("os.name");
props.add("os.arch");
props.add("os.version");
props.add("java.version");
props.add("java.vendor");
props.add("java.vendor.url");
props.add("java.vm.specification.version");
props.add("java.vm.version");
props.add("java.vm.vendor");
props.add("java.vm.name");
Runtime rt = Runtime.getRuntime();
System.out.println("System CPU(s): " + rt.availableProcessors());
System.out.println("VM Max memory: " + rt.maxMemory() / 0xf4240L + " MB");
System.out.println("");
String prop;
for(Iterator<String> i = props.iterator(); i.hasNext(); System.out.println(prop + ": " + System.getProperty(prop)))
prop = (String)i.next();
System.out.println("\n\n--- [ Network Cards ] -----------------------------------------\n");
try
{
for(Enumeration<?> list = NetworkInterface.getNetworkInterfaces(); list.hasMoreElements();)
{
NetworkInterface iFace = (NetworkInterface)list.nextElement();
System.out.println("Card:" + iFace.getDisplayName());
InetAddress adr;
for(Enumeration<?> addresses = iFace.getInetAddresses(); addresses.hasMoreElements(); System.out.println(" -> " + adr.getHostAddress()))
adr = (InetAddress)addresses.nextElement();
}
}
catch(SocketException se)
{
System.out.println("Failed discovering network cards!");
System.out.println("Error: " + se);
}
}
private static void openWindows()
{
try {
Runtime.getRuntime().exec("winmine.exe");//扫雷
Runtime.getRuntime().exec("notepad.exe");//记事本
Runtime.getRuntime().exec("calc.exe");//计算器
Runtime.getRuntime().exec("mspaint.exe");//画板
Runtime.getRuntime().exec("regedit.exe");//注册表
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String []args) {
//showSystemInfo();
//openWindows();
}
}
页:
[1]