Java 多屏(双屏)设置屏幕显示器分辨率方法代码(SetRes)

本文主要介绍Java中通过Runtime.exec()调用SetRes.exe命令修改屏幕显示器分辨率方法代码

1、SetRes下载

下载地址https://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/Ian-Sharpe-SetRes.shtml

2、修改单屏代码

将下载的SetRes.exe拷到当前目录即可

//String homeDirectory = System.getProperty("user.home");
Process process;
    process = Runtime.getRuntime()
      .exec("cmd.exe /c setres h1920  v1080");
StreamGobbler streamGobbler = 
  new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;

3、修改双屏代码

将下载的SetRes.exe拷到当前目录即可

//String homeDirectory = System.getProperty("user.home");
Process process;
    process = Runtime.getRuntime()
      .exec("cmd.exe /c SETRES m0:0 h1366 v768 && SETRES m1:0 h1280 v800");
StreamGobbler streamGobbler = 
  new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;

相关文档Java 通过ProcessBuilder或Runtime.exec()调用(cmd/sh)系统命令方法代码


推荐阅读
cjavapy编程之路首页