大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
1、需要用到psexec.exe,网上都可以下载到
private static final int TIME_OUT = 2000;
private final static String ip = "192.168.70.**";
private final static String username = "Administrator";
private final static String passwd = "**";
/**
* 执行远程电脑下的脚本
*/
private final static String command = "c:\\test.bat";
public static void main(String[] args) throws IOException, InterruptedException {
Process p;
String cmd = "c:\\\\psexec \\\\" + ip + " -u " + username + " -p " + passwd + " -s " + command;
//执行命令
p = Runtime.getRuntime().exec(cmd);
p.waitFor(TIME_OUT, TimeUnit.MILLISECONDS);
BufferedReader errReader =
new BufferedReader(new InputStreamReader(p.getErrorStream(), "GBK"));
String errString = errReader.readLine();
if (!StringUtils.isEmpty(errString)) {
System.out.println("fail");
} else {
System.out.println("success");
}
}
2、使用wmic
private static final int TIME_OUT = 2000;
private final static String ip = "192.168.0.181";
private final static String username = "administrt";
private final static String passwd = "0823";
/**
* 执行远程电脑下的脚本
*/
private final static String command = "shutdown -r";
public static void main(String[] args) throws Exception {
char[] chars = new char[1024];
Process p;
String cmd = "wmic /node:" + ip + " /user:" + username + " /password:" + passwd + " process call create \"cmd.exe /c " + command
+ ">d:\\result.txt\"";
//执行命令
p = Runtime.getRuntime().exec(cmd);
// p.waitFor(TIME_OUT, TimeUnit.MILLISECONDS);
BufferedReader errReader =
new BufferedReader(new InputStreamReader(p.getErrorStream(), "GBK"));
errReader.read(chars);
String errString = new String(chars);
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream(), "GBK"));
reader.read(chars);
String string = new String(chars);
System.out.println(string);
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/190200.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...