从Java启动应用程序处于最小化状态 [英] Launch Application in a minimized state from Java

查看:127
本文介绍了从Java启动应用程序处于最小化状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我之前提出的问题的后续问题:

This is a followup question to one I previously asked:

start-program-if-not-already-in-java

我没有得到一个很好的解决方案(因为似乎没有一个),但我有一个相关的问题:

I didn't get a great solution there (as there doesn't appear to be one), but I have a related question:

无论如何使用Java代码(Windows中的.exe,而不是Java应用程序)启动应用程序并使其最小化?或者也许在开始后立即将其最小化?这将解决另一个问题的焦点问题,已经运行的问题或多或少会处理它自己。

Is there anyway to launch an application in Java code (an .exe in Windows, not a Java app) and have it start minimized? Or perhaps to minimize it right after start? That would solve the focus issue from the other question and the already running problem would more or less deal with itself.

再次澄清问题:Java客户端和.exe是在Windows中运行,我真的没有能力编写任何包装器或使用JNI mojo或类似的东西。我或多或少需要一个纯Java解决方案。

Clarification issues again: the Java client and the .exe are running in Windows and I really don't have the ability to write any wrappers or make use of JNI mojo or anything like that. I more or less need a pure Java solution.

再次感谢您的帮助,我非常愿意接受一个简单的答案:这不是可能。

Again, thanks for the help and I am more than willing to accept an answer that is simply: "This is just not possible."

推荐答案

仅限Windows:

public class StartWindowMinimized {

  public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      System.err
          .println("Expected: one argument; the command to launch minimized");
    }
    String cmd = "cmd.exe /C START /MIN ";
    Runtime.getRuntime().exec(cmd + args[0]);
  }

}

样本用法:

java -cp . StartWindowMinimized notepad.exe
java -cp . StartWindowMinimized cmd.exe

要理解所涉及的参数:

cmd /?
START /?

这篇关于从Java启动应用程序处于最小化状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆