问题描述
我的问题是,我想在窗口启动后通过批处理文件最小化窗口。
My problem is that I want to minimize a window via batch file after window-start.
如何通过cmd最小化应用程序窗口? pid是已知的。我的操作系统是win7。
How to minimize a application-window from cmd? The pid is known. My OS is win7.
推荐答案
这里是一个Batch / VBScript解决方案,不需要额外的软件:
Here is a Batch/VBScript solution which requires no additional software:
@echo Off
if \{%1\}==\{\} @echo Syntax: MinimizePID PID & goto :EOF
if exist "%TEMP%\MinimizePID.vbs" del /f %TEMP%\MinimizePID.vbs
@echo dim objArguments, pid>"%TEMP%\MinimizePID.vbs"
@echo Set WshShell = CreateObject("WScript.Shell")>>"%TEMP%\MinimizePID.vbs"
@echo Set objArguments = Wscript.Arguments>>"%TEMP%\MinimizePID.vbs"
@echo pid = objArguments(0)>>"%TEMP%\MinimizePID.vbs"
@echo WshShell.AppActivate pid>>"%TEMP%\MinimizePID.vbs"
@set "line=%%+ n"
setlocal EnableDelayedExpansion
(
@echo WshShell.SendKeys "!line!">>"%TEMP%\MinimizePID.vbs"
)
:doit
cscript //nologo "%TEMP%\MinimizePID.vbs" %1
假设pid.txt具有要最小化其窗口的进程的PID。将此批处理文件保存为MinimizePID.bat,并以这种方式调用它:
Assume pid.txt has the PID of the process whose window you want to minimize. Save this batch file as MinimizePID.bat and invoke it in this way:
for /f %i in (pid.txt) do call MinimizePID %I
这里唯一棘手的部分是让SendKeys发送Minimize窗口命令。你可能将它编码为纯粹的VBScript。此外,请注意,此操作只适用于美国Windows。本地化版本中的快捷键不同。
The only tricky part here was getting the SendKeys to work to send the Minimize window command. You probably could code this as purely VBScript. Also note this will work only on US Windows - key shortcuts are different in localized versions.
Thanks to How can I maximize, restore, or minimize a window with a vb script? for the approach.
这篇关于通过其pid最小化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!