How to open `cmd.exe` maximized from the explorer context menu?

I am trying to set up the new Windows Subsystem for Linux (WSL) to open from the context menu:

enter image description here

So far I followed the tutorial on http://winaero.com/blog/add-bash-to-the-folder-context-menu-in-windows-10/, and was able to add it as on the image above. The process is basically set the following Windows Registry:

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\openbashhere]
@="Open Bash Here"
"Icon"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,5c,00,41,00,70,00,70,00,44,00,61,00,74,00,61,00,5c,00,4c,00,\
  6f,00,63,00,61,00,6c,00,5c,00,6c,00,78,00,73,00,73,00,5c,00,62,00,61,00,73,\
  00,68,00,2e,00,69,00,63,00,6f,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\openbashhere\command]
@="cmd.exe /c cd /d \"%V\" && bash.exe"

Here the problem is the line "cmd.exe /c cd /d \"%V\" && bash.exe", I could not figure out a command to correctly open it maximized. I searched and found some threads about it:

  1. maximizing the windows Command prompt
  2. Why doesn't the Windows command prompt window maximize to the full screen size?
  3. Adding Bash on Ubuntu on Windows 10 to Explorer Context Menu (Issues)
  4. How can I launch cmd.exe minimized?

I tried to do this tricky play:

cmd.exe /c start /max cmd.exe

It works if I type it on the Run dialog:

enter image description here

But if I try to put it on the above registry entry, it does not open it maximized:

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\openbashhere\command]
@="cmd.exe /c start /max cmd.exe /c cd /d \"%V\" && bash.exe"

Later I also tried another dirty trick with a shortcut to "C:\ProgramData\Microsoft\Windows\Start Menu\cmd.exe.lnk", which opens the cmd maximixed, but when I put it in place of the cmd.exe:

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\openbashhere\command]
@="\"C:\ProgramData\Microsoft\Windows\Start Menu\cmd.exe.lnk\" /c cd /d \"%V\" && bash.exe"

Windows throws this error:

enter image description here


Solution 1:

Read about the && command separator:

commandA && commandB             Run commandA, if it succeeds then run commandB

In your @="cmd.exe /c start /max cmd.exe /c cd /d \"%V\" && bash.exe":

  • commandA = start /max cmd.exe /c cd /d \"%V\"
  • commandB = bash.exe

Hence, bash.exe is launched from the first/outer cmd /c instance (unmaximized, generally).

Moreover, read about title in start command.

Use either (escape ampersands)

@="cmd.exe /c start \"\" /max cmd.exe /c cd /d \"%V\" ^&^& bash.exe"

or, maybe better (omit inner cmd /c at all)

@="cmd.exe /c cd /d \"%V\" && start \"\" /max bash.exe"