0

Windows+R or the "start" command are pretty powerful. I can start Google Chrome with Windows + R "chrome". However, chrome would not start when I type "chrome" in a running cmd.exe - since it is not listed in PATH. So i wonder where "Run" looks up what to start?

I'm trying to get the same information programmatically and up until now I was fine checking if the "genericCommand" or "genericCommand.exe" exists within one of the PATH directories. Works for "notepad", "mspaint" etc. But not for "chrome".

I want to programmatically map a given command to the program executed when started with Windows run or the "start" command.

Why? Any ideas?

Matthias
  • 1,267
  • 1
  • 15
  • 27

2 Answers2

2

Take a look at the registry key:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

This is an alternate list of commands (in addition to applications in %PATH% directories)

This is where you can override some defaults - say, for example, you want to replace cmd.exe with cmdr.exe.

Another example that I use this for is adding an "np" alias for notepad++.exe. Create a sub-key called "np.exe" with a default value of "C:\Program Files (x86)\Notepad++\notepad++.exe". So from the run dialog I can type "np c:\temp\something.txt" and open it in np++.

Anything in this registry key will be considered higher priority than anything in %PATH%. Which is why you can override cmd.exe and others by adding them here.

Adam Plocher
  • 13,994
  • 6
  • 46
  • 79
1

Thx a lot. That's what I came up with:

    private static string GetCommandPathFromRegistry(string commandNameWithExeEnding)
    {
        var localMachineRegistryKey = Registry.LocalMachine;
        localMachineRegistryKey = localMachineRegistryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths");
        var commandSubKey = localMachineRegistryKey.OpenSubKey(commandNameWithExeEnding);
        return commandSubKey?.GetValue("")?.ToString();
    }

BR Matthias

Matthias
  • 1,267
  • 1
  • 15
  • 27
  • 1
    The code is fine, but it is incomplete. See answers on [Where is “START” searching for executables?](http://stackoverflow.com/a/27386403/3074564) and [How to enumerate all programs that can open XML file as plain text?](http://stackoverflow.com/a/31603179/3074564) – Mofi Nov 22 '16 at 06:40
  • I see. Thx. It's a shame that there is no way to get the programs name that start would launch. like with a parameter or so. i really don't feel like duplicating all the features of start. :( – Matthias Nov 22 '16 at 23:42
  • Well, on using Visual C++ the function [ShellExecuteEx](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154.aspx) can be used to run an application with unknown path from within a C++ coded application like `start` does it from command line. – Mofi Nov 23 '16 at 06:52
  • i dont want to run it. i only need the path of the file that would be executed! – Matthias Nov 25 '16 at 11:31