Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmd start command ignores /min switch

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.

like image 698
Anonymous Avatar asked Jun 30 '26 21:06

Anonymous


2 Answers

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.

like image 181
MC ND Avatar answered Jul 02 '26 12:07

MC ND


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.

like image 24
Lee Cottrell Avatar answered Jul 02 '26 12:07

Lee Cottrell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!