5

I know I can create custom keyboard shortcuts in Windows (7 and XP, at least) by creating a new shortcut to a program, navigating to Properties on the file shortcut, and setting the "Shortcut Key" field. Strangely, however, when this keyboard shortcut is invoked, it does not always spawn a new instance of the program. Rather, if a program instance is not already spawned, it will spawn a new instance; and if a program instance is already spawned, then it will focus that window.

How can I make a windows keyboard shortcut that spawns a new instance of the linked program, regardless of whether there is already a running instance of the linked program?

  • Is this behavior identical for all programs? – Daniel Beck Dec 22 '11 at 6:36
  • Does it happen to applications for which you are able to open multiple instances otherwise ? – Shekhar Dec 22 '11 at 6:41
  • This happens for all the programs I've tested, including cygwin and notepad. – jbeard4 Dec 22 '11 at 6:45
6

I seem to be the AutoHotkey ambassador here on Superuser. Here is a simple script to launch a new process each time:

#n::
Run notepad.exe
Exit
  • #n:: is the keyboard shortcut; e.g. Windows+N.
  • Run opens an external program; e.g. notepad.exe
  • Exit ends the current thread/script.
  • That's the way to do it! – jbeard4 Dec 22 '11 at 7:01
  • Did you try it? I tested it a bit, and it created a new process each time. Let me know if you find out otherwise. :) – iglvzx Dec 22 '11 at 7:03
  • It's a good way to achieve it, but when using an external program you add another 'patch' to the OS, instead of using a built-in feature – BornToCode Jun 27 '13 at 8:32
  • Check Axel Siebert's solution for a fix without an external program! :) – hopla Jul 27 '18 at 14:53
  • @iglvzx thank you. Do you know how to not create a new process each time? – whitesiroi Aug 17 '18 at 12:44
6

I know this is a very old question but I had a similar problem and found a solution that doesn't require a third party application.

In windows 7/8, you can switch to apps quickly by pressing Windows+[number] where number is the position of the application on the taskbar. You can also pin your apps to the taskbar using the right click context menu. Lastly, you can start new instances of an app on the taskbar by pressing Windows+Shift+[number]. This works very well for me when I want to start new instances of cygwin, where I typically have 3+ windows and multiple monitors; I have cygwin pinned to by taskbar so the [number] does not change, and I can quickly start new instances and switch between currently running instances easily using the windows key.

Hope that helps everyone out there!

  • This was what I was looking for! Need lots of Bash for Windows terminals open at different times. Thanks! :) – armadadrive Oct 26 '16 at 19:13
2

There is a direct solution without any helper programs - just use this shortcut target:

%comspec% /c start notepad

If the actual target has a path with spaces, the syntax becomes

%comspec% /c start "" "C:\Program Files (x86)\Foo\bar.exe"

Configure the shortcut to run minimized to avoid the console window flash.

  • I think this is a great solution! I used to have my keyboard shortcut on a VBS script which ran: CreateObject("Wscript.Shell").Run "C:\whatever.exe", 1, False But then you need to put the script somewhere etc. This is much cleaner, be sure the configure the shortcut to run minimized hower, as you said. Otherwise the flicker starts to get annoying :) Thx for this! – hopla Jul 27 '18 at 14:51
1

I had the same problem with my Cygwin keyboard shortcut and after a bit of research I found this lifehacker article:

Shortcut keys work differently depending on the location of the shortcut. If the shortcut is on the desktop or in the Start menu hierarchy, you can use its shortcut key to start the assigned program, or switch to the program if it is already running.

If the shortcut is not on the desktop or in the Start menu hierarchy, you cannot use its shortcut key to start the assigned program, but you can use its shortcut key to switch to the assigned program if it is already running.

I noticed that running Cygwin.bat by default starts a bash login shell inside the Windows Command Prompt which is not what I wanted. What I wanted was an instance of mintty running the bash login shell. I found this really helpful documentation that helped sort out my shortcut dilemma.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.