windows 使用批处理脚本最小化或关闭程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/838862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:19:43  来源:igfitidea点击:

Minimizing or closing a program with batch script

windowsbatch-file

提问by Sakkle

I am writing a batch script intended for handling some tasks in my (and a few colleagues) windows startup. The main thing that needs to happen is the killing of a few processes that do to this being a large corporate environment are started as default. They interfere with our work so we have to kill them... I know it's stupid but thats beside the point. This is can not be changed and we have to make due.

我正在编写一个批处理脚本,用于处理我(和一些同事)windows 启动中的一些任务。需要发生的主要事情是杀死一些进程,这些进程在默认情况下启动大型企业环境。他们干扰了我们的工作,所以我们必须杀死他们……我知道这很愚蠢,但这无关紧要。这是无法改变的,我们必须做出适当的安排。

I thought about adding some more useful functionality to the script, like starting up certain programs and so on. This all works decently well but the problem i have is that the OUClient won't start minimized. It doesn't open a window (so it is minimized to some extent) but it still appears in the alt-tab list, witch it doesn't when i minimize or close it manually. This is the script:

我想在脚本中添加一些更有用的功能,比如启动某些程序等等。这一切都运行良好,但我遇到的问题是 OUClient 不会开始最小化。它不会打开一个窗口(因此它在某种程度上被最小化)但它仍然出现在 alt-tab 列表中,当我手动最小化或关闭它时它不会。这是脚本:

@echo off
C:
cd "C:\Program Files\SysInternals\"

pskill flxps12.exe
pskill flxps17.exe

start /minimized "" "C:\Program Files\Osiris Data\OUClient\OUClient.exe"
start "Outlook" "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
start "Explorer" "C:\Program Files\Internet Explorer\iexplore.exe"

cls
@exit

So the question is: How can I make the OUClient minimize, or even better closeto the system tray (like if you clicked the red x in the upper right) after it is started.

所以问题是:如何使 OUClient 在启动后最小化,甚至更好地靠近系统托盘(就像您单击右上角的红色 x)。

We are running this on Windows XP SP2.

我们在 Windows XP SP2 上运行它。

EDIT: Everything works fine except the /minimize on OUClient.

编辑:除了 OUClient 上的 /minimize 之外,一切正常。

回答by Joey

There is no way to do this from batch files directly, but you can write a little helper program which finds a windowand then uses ShowWindowto minimize it. Unfortunately this doesn't seem to be easily available from VBScript which would have made this a little easier.

无法直接从批处理文件中执行此操作,但是您可以编写一个小帮助程序来查找一个窗口,然后使用ShowWindow将其最小化。不幸的是,这似乎不容易从 VBScript 中获得,这会使这更容易一些。

回答by anonymous coward

The minimizedswitch has a forward slash, not a backslash.

minimized交换机具有正斜杠,而不是反斜杠。

I don't know if OUClient will respect that, but it should.

我不知道 OUClient 是否会尊重这一点,但它应该。

回答by subZero

Have you had a look at the TASKKILL command? A basic example would be

你有没有看过 TASKKILL 命令?一个基本的例子是

TASKKILL /IM /F iexplore.exe

TASKKILL /IM /F iexplore.exe

(yes, who wouldn't want to kill iexplore? ;-))

(是的,谁不想杀死 iexplore?;-))

Best.

最好的事物。