Saturday, August 5, 2017

windows - Registry: Shell Open Command - Open multiple programs


I'm trying to register a shell open command via the registry and want to open more than one program, so I tried it like this:


[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\myFile\Shell\Open\Command]
@="cmd /k calc & notepad & exit"

calc and notepad are just an example to demonstrate it.


If I use it like this, the calculator and Notepad are opened, but the command prompt is still open until I close Notepad. If I change it to cmd /k calc & calc & exit, I get 2 calculator instances and the command prompt is closed as I want it.


Why is it not working with Notepad?


Does anybody know another way to start multiple programs with the shell open command in the registry without having the command prompt stay open?


Answer



You can do this by instead using the following command:


cmd /k start calc & start notepad & exit

Therefore making your .reg file into:


[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\myFile\Shell\Open\Command]
@="cmd /k start calc & start notepad & exit"

The reason why calc works fine (in Windows 10, but not in Windows 7) is that the calc.exe process starts a different process (Calculator.exe) and then exits, allowing the command to proceed.


This isn't so for notepad.exe, which means that the command gets stuck there waiting for notepad.exe to close.


The start command is used to start a process in a separate window so that cmd can continue with the next step.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...