问题
I'm running windows 2012 and whenever I type this in console:
start /min calc.exe
It opens the application but, it's not minimized to taskbar.
On Windonws 8.1 it actually does minimize it.
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.
My real goal is to launch python and chrome minimized in Win 2012 R2 via command line.
Both of them do launch minimized in 8.1 when using the /min switch.
回答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.
Inside this structure, there is a wShowWindow
member to indicate how to show the window of the started process. Its documentation states
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. Otherwise, this member is ignored.
For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored wShowWindow specifies the default value. In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT.
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.
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.
note 2: As already commented, in some cases (my case, windows 10, calc.exe
) you start a process and it starts another one. You have not control on the second started process.
回答2:
I could not do this in Command Prompt but was able to do this in PowerShell. Since you are on 2012, install the Powershell ISE from Server Manager | Manage | Add roles and features.
First I created the function from this page Set Window Style function
Then I wrote these lines (Python may be named differently on your computer)
(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.
回答3:
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. Link: 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
Hope it helps you!
来源:https://stackoverflow.com/questions/43160012/cmd-start-command-ignores-min-switch