调用 windows 系统 cmd 命令
package com.wretchant.fredis.util;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.project.Project;
import java.io.IOException;
/**
* @author Created by 谭健 on 2020/8/6. 星期四. 17:30.
* © All Rights Reserved.
* <p>
* 调用 windows 系统 cmd 命令
*/
public class WinCmdUtils {
/**
* 打开默认浏览器访问指定链接命令
*
* @param url 指定链接
* @return 命令
*/
public static String getChromeUrlCmd(String url) {
return "rundll32 url.dll,FileProtocolHandler " + url;
}
/**
* windows 系统控制命令
*/
public enum ControlRunDLL {
HOME("rundll32.exe shell32.dll,Control_RunDLL", "控制面板主页"),
FIREWALL("RunDll32.exe shell32.dll,Control_RunDLL firewall.cpl", "打开防火墙"),
_1("RunDll32.exe shell32.dll,Options_RunDLL 1", "打开任务栏属性"),
SYSDM("RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,5", "打开计算机远程设置"),
NCPA("RunDll32.exe shell32.dll,Control_RunDLL ncpa.cpl", "网络连接"),
MAIN_CPL("Rundll32 Shell32.dll,Control_RunDLL main.cpl @0,0", "打开鼠标设置"),
LOCK_WORK_STATION("RunDll32.exe user32.dll,LockWorkStation", "锁屏"),
TIME_DATE("RunDll32.exe shell32.dll,Control_RunDLL timedate.cpl", "调整日期和时间"),
DESK_3("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3", "打开显示设置"),
SYSTEM("rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl @1", "修改计算机名称");
ControlRunDLL(String value, String functionDescribe) {
this.value = value;
this.functionDescribe = functionDescribe;
}
public String getValue() {
return value;
}
public String getFunctionDescribe() {
return functionDescribe;
}
/**
* 命令
*/
private final String value;
/**
* 功能描述
*/
private final String functionDescribe;
}
public static void openChromeUrl(Project project, String url) {
cmd(getChromeUrlCmd(url));
String msg = "打开 " + url + " 成功";
NotifyUtils.notifyUser(project, msg, NotificationType.INFORMATION);
}
public static void windowsRunDLL(Project project, ControlRunDLL runDLL) {
cmd(runDLL.getValue());
NotifyUtils.notifyUser(project, runDLL.getFunctionDescribe(), NotificationType.INFORMATION);
}
public static Process cmd(String cmd) {
try {
return Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
转载:https://blog.csdn.net/qq_15071263/article/details/108078600
查看评论