Friday 19 April 2019

How does the start batch command execute a software by calling only its name?



For example I launch superuser.com via firefox by this command:


start firefox http://superuser.com

How does "start" know where is my firefox.exe? I guess it reads it from registy (it is not defined in my PATH) but then how is the start command and the registry of the OS is interconnected? Exactly which registries are used?



Answer



Yes, this information is stored in the registry.


The key


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

has subkeys for every application that you can run directly without being in the path.


The subkey firefox.exe has two values:


(Default)    C:\Program Files\Mozilla Firefox\firefox.exe
Path C:\Program Files\Mozilla Firefox\

The first value specifies the full path of the executable, the second the directory it should run in.


Application Registration (Windows) explains in details where Windows would search for the firefox executable:



When the ShellExecuteEx function is called with the name of an executable file in its lpFile parameter, there are several places where the function looks for the file. We recommend registering your application in the App Paths registry subkey. Doing so avoids the need for applications to modify the system PATH environment variable.


The file is sought in the following locations:



  • The current working directory.

  • The Windows directory only (no subdirectories are searched).

  • The Windows\System32 directory.

  • Directories listed in the PATH environment variable.

  • Recommended:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths



No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...