java 关闭其他应用程序或重启机器

阅读更多
public static Process performCommand(String command) {
//command:命令
  try { 
   return Runtime.getRuntime().exec(command); 
  } catch (IOException e) { 
   e.printStackTrace(); 
   return null; 
  } 
}
例:1、重启机器
String commd="C:\\Windows\\System32\\shutdown -r -f -t 0";
Process pro=performCommand(commd);
2、管理某一应用进程
String command="taskkill /f /im DecodingOnWallService.exe";
Process pro=performCommand(command);
3、启动某一应用进程
String exePath="d\\decodeServer\\DecodingOnWallService.exe";
Process startPro=performCommand(exePath);

你可能感兴趣的:(java,Runtime,执行命令)