我没有尝试过任何编码,因为我没有经验。
但是对于我目前正在制作的一个应用程序(为了一个任务),我想让用户在倒计时结束时打开省电模式,(如果用户之前选中了“休息时打开省电模式”复选框)软件将自动启用省电模式。(操作系统- Windows 10)。
发布于 2020-07-07 15:46:39
您可以通过ProcessBuilder执行cmd命令来实现此类操作。我已经准备好了一个适合我的程序:
public static void main(String[] args) throws Exception {
JPanel panel = new JPanel();
JFrame frame = new JFrame();
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
JButton button = new JButton("Standby");
panel.add(button);
frame.setVisible(true);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "rundll32.exe powrprof.dll,SetSuspendState");
builder.redirectErrorStream(true);
try {
builder.start();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}也许您需要将命令"rundll32.exe powrprof.dll,SetSuspendState“更改为其他命令。
https://stackoverflow.com/questions/62769584
复制相似问题