2

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anonymous
  • 4,692
  • 8
  • 61
  • 91
  • Might be a peculiarity of `calc.exe`. If you try the same with `cmd.exe`, it operates as expected. – Axel Kemper Apr 01 '17 at 18:17
  • In windows 10 it also doesn't minimize, I guess due to the fact that it is an UWP app. –  Apr 01 '17 at 18:18
  • That's interesting. cmd.exe is launching minimzed. However, I want to launch Python and Chrome apps minimized, and it doesn't work. Still can't understand why, because it works on Windows 8.1 – Anonymous Apr 01 '17 at 18:50
  • Do you mean Windows Server 2012 R2? That's the server version corresponding to Windows 8.1. – Harry Johnston Apr 01 '17 at 21:45
  • Yes, that's the one I'm running, I'm also connecting to it via RDP. – Anonymous Apr 01 '17 at 22:07
  • Strangely enough, minimized start does work for `notepad.exe` but not for `explorer.exe`. I guess, it is up to the application, to take the start condition seriously. – Axel Kemper Apr 01 '17 at 22:08
  • explorer.exe has always been full of bull shit – Anonymous Apr 01 '17 at 22:16
  • Some applications support starting with minimized window and being therefore in background and some do not. Windows Notepad is an example which supports minimized start while Windows Calculator does not support a minimized start. Firefox can be started also with minimized window using `start /min`, but only if it was last time not exited with maximized window. I suppose this is true for Chrome, too. Start Chrome, click on icon for restore window, resize the window to fill entire screen and exit it. Now start Chrome with `start /min`. Does Chrome start with minimized window in background? – Mofi Apr 02 '17 at 12:57
  • As I said, everything works fine on win8.1 (this includes calculator, notepad, python and chrome... except only explorer). – Anonymous Apr 02 '17 at 13:03
  • Windows Calculator on Windows XP never starts minimized, but Notepad always does. It was interesting for me to read that on Windows 8.1 `calc.exe` supports starting minimized. Well, the calculator cannot be used without user interaction (in general) and therefore it really does not make sense to start it with minimized window. Other applications like text editors or browsers can be used also without user interactions which might be the reason why those applications support starting minimized. It is a matter of the application and not of `start` if starting minimized works or not. – Mofi Apr 02 '17 at 13:05
  • If it was a matter of application, it would show the same behavior in win8 and windows 2012. on my windows 2012 NOTHING starts minimized. – Anonymous Apr 02 '17 at 14:53
  • 2
    Not sure about windows 2012, in windows 10 the `calc.exe` starts another executable (`calculator.exe`) . You can request the minimization of the first, but you have not control on how the second is launched. – MC ND Apr 02 '17 at 15:26
  • Try installing the Desktop Experience feature, [found under "User Interfaces and Infrastructure"](https://blogs.technet.microsoft.com/meamcs/2012/05/01/how-to-add-desktop-experience-feature-on-windows-server-2012-server-8-beta/) on Server 2012 R2. That's the only relevant difference between 8.1 and 2012 R2 that I can think of. One other random thought: does the 2012 R2 machine have a much lower screen resolution? If Windows thinks it is running on a tablet or tablet-like machine, minimization behaviour might be affected. – Harry Johnston Apr 02 '17 at 21:12
  • Interesting, I'll check it out about the desktop experience feature. Regarding the resolution, I'm launching it 1920x1080 and my desktop is 1440p. – Anonymous Apr 02 '17 at 21:59
  • Is 1920x1080 the native resolution of the display (if any) attached to the server, or is it a remote connection? – Harry Johnston Apr 02 '17 at 23:14
  • A remote connection... it doesn't have a display – Anonymous Apr 03 '17 at 00:02
  • Try watching it in procmon to see if there's any clues – Bali C Apr 06 '17 at 12:18

3 Answers3

7

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.

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Is there any alternative cmd command I could try? Perhaps calling CreateProcess directly from command line? I would love some examples. – Anonymous Apr 08 '17 at 01:21
  • @Anonymous, Directly calling the CreateProcess (something that the start command already does) will have the same problem. Realize that tools as Nirsoft's [AdvancedRun](http://www.nirsoft.net/utils/advanced_run.html) also warns in its window handling *"Be aware that this option only affects programs that support it"*. Ì've tested `chrome.exe` and `python.exe` and both accept the `start /min` in windows 10, but whatever any of them do after starting is out of the control of the `start` command. – MC ND Apr 08 '17 at 07:35
  • @MCND, I suspect the OPs issue is a variant of a similar problem reported on tablets, where Windows quite deliberately fails to pass the flag on to the new application. – Harry Johnston Apr 10 '17 at 21:08
  • @HarryJohnston, maybe you are right (in windows 10, in tablet mode chrome starts minimized sometimes, others not) unfortunately I'm limited to Windows 7 and 10 and can not test in the OP environment . In any case, as indicated, directly using what the OS provides all you can do is to ask the system to minimize the window on start. Even the approach in Lee Cottrell's answer (start in whatever state and then minimize) will fail for the windows 10 `calc` case. Without writting specific code for the task I don't see a clear way to deal with OP problem. – MC ND Apr 10 '17 at 21:43
  • From a SO perspective I agree. If I'm right (which I'm not at all sure of) this might be more of a Server Fault question. – Harry Johnston Apr 11 '17 at 01:23
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.

1

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!

Totoo
  • 139
  • 11