简体   繁体   English

Cmd start命令忽略/ min开关

[英]Cmd start command ignores /min switch

I'm running windows 2012 and whenever I type this in console: 我正在运行Windows 2012,并且每当在控制台中键入以下命令时:

start /min calc.exe

It opens the application but, it's not minimized to taskbar. 它会打开应用程序,但不会最小化到任务栏。

On Windonws 8.1 it actually does minimize it. 在Windonws 8.1上,实际上确实将其最小化。

Any ideas why? 有什么想法吗?

Edit: I want to be specific about this question as it is getting confused. 编辑:由于这个问题我很困惑,我想具体说明。

calc.exe above was just an example to demonstrate that /min switch is not working. 上面的calc.exe只是一个示例,用来演示/ min开关不起作用。

My real goal is to launch python and chrome minimized in Win 2012 R2 via command line. 我的真正目标是通过命令行在Win 2012 R2中启动最小化的pythonchrome

Both of them do launch minimized in 8.1 when using the /min switch. 当使用/ min开关时,它们都在8.1中最小化启动。

start /min file.exe uses CreateProcess API call to start the process, with the adecuated information inside the STARTUPINFO structure pointed by the lpStartupInfo argument. start /min file.exe使用CreateProcess API调用来启动进程,并在lpStartupInfo参数所指向的STARTUPINFO结构中包含相关信息。

Inside this structure, there is a wShowWindow member to indicate how to show the window of the started process. 在此结构内部,有一个wShowWindow成员以指示如何显示已启动进程的窗口。 Its documentation states 其文档说明

wShowWindow wShowWindow

If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of the values that can be specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. 如果dwFlags指定STARTF_USESHOWWINDOW,则该成员可以是ShowWindow函数的nCmdShow参数中可以指定的任何值,SW_SHOWDEFAULT除外。 Otherwise, this member is ignored. 否则,将忽略此成员。

For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored wShowWindow specifies the default value. 对于GUI进程,第一次调用ShowWindow时,将忽略其nCmdShow参数wShowWindow指定默认值。 In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT. 在随后的ShowWindow调用中,如果ShowWindow的nCmdShow参数设置为SW_SHOWDEFAULT,则使用wShowWindow成员

That is, you depend on how the started process handles its window management. 也就是说,您取决于启动的进程如何处理其窗口管理。 There is nothing you could do in the start command to ensure the new window will be minimized. start命令中您无法做任何事情来确保将新窗口最小化。

note : start command uses CreateProcess in the case of executable files, but different arguments (a document, a URL, ...) lead to different APIs used (Ex. ShellExecute or ShellExecuteEx ), but you end in the same problem after following a different path. 注意 :对于可执行文件, start命令使用CreateProcess ,但是不同的参数(文档,URL等)导致使用的API不同(例如ShellExecuteShellExecuteEx ),但是在执行以下命令后,您将遇到相同的问题不同的路径。

note 2 : As already commented, in some cases (my case, windows 10, calc.exe ) you start a process and it starts another one. 注意2 :如前所述,在某些情况下(例如Windows 10, calc.exe ),您启动一​​个进程,然后启动另一个进程。 You have not control on the second started process. 您无法控制第二个启动过程。

I could not do this in Command Prompt but was able to do this in PowerShell. 我无法在命令提示符下执行此操作,但能够在PowerShell中执行此操作。 Since you are on 2012, install the Powershell ISE from Server Manager | 由于您在2012年,请从服务器管理器|安装Powershell ISE。 Manage | 管理| Add roles and features. 添加角色和功能。

First I created the function from this page Set Window Style function 首先,我从该页面创建了该功能Set Window Style function

Then I wrote these lines (Python may be named differently on your computer) 然后,我写了以下几行(Python在您的计算机上的命名可能不同)

 (Get-Process -Name Python).MainWindowHandle | foreach { Set-WindowStyle MINIMIZE $_ }
 (Get-Process -Name Chrome).MainWindowHandle | foreach { Set-WindowStyle MINIMIZE $_ }

Finally, I saved this as a script and pasted it on the desktop. 最后,我将其另存为脚本并粘贴到桌面上。

You didn't wrote, that you don't want to use any tools, so here is one, that could solve your problem. 您没有写过,您不想使用任何工具,所以这里有个可以解决您问题的工具。 No need to install, it is from a trusted distributor (Nirsoft), so you should give it a try. 无需安装,它来自受信任的发行商(Nirsoft),因此您可以尝试一下。 Link: http://www.nirsoft.net/utils/advanced_run.html 链接: http//www.nirsoft.net/utils/advanced_run.html

First you have to create a config file via gui, than you can start the probram by calling AdvancedRun.exe /run config.cfg 首先,您必须通过gui创建配置文件,然后才能通过调用AdvancedRun.exe / run config.cfg来启动probram。

Hope it helps you! 希望对您有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM