Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

windows - Where is "START" searching for executables?

In my company we use a batch-file to start Matlab. The batch-file prepares the environment before starting Matlab.

Matlab itself is started with

START MATLAB.EXE

I have several versions of Matlab installed on my system. And this command is starting the wrong Matlab version. Where is START looking for the executables?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Command start finds executables to run like command line interpreter cmd.exe does if no absolute path is used, using additionally the extensions listed in environment variable PATHEXT separated by semicolons if file extension is also missing.

  1. Current working directory.

  2. All directories of environment variable PATH in order as listed in PATH.

    Just type in a command prompt window set path to see all directories in PATH as well as all file extensions in PATHEXT.

    Please note that each user account has its own PATH. Therefore PATH of system account is usually different to PATH of a standard user account. That is very important on running a batch file with command runas or via task scheduler using a different account.

    The batch file posted by Jason Faulkner is very helpful here, too.

  3. start looks further in registry under the keys

    HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionApp Paths
    HKEY_CURRENT_USERSoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp Paths
    HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionApp Paths
    HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftWindowsCurrentVersionApp Paths

    Applications installed with an MSI package (embedded in installer EXE or published separately) using msiexec have their file name registered under App Paths with default string value containing name of executable with full path. There is often a second string value with name Path containing just the full path to the executable of the application. Other installers register an application also in App Paths, see Microsoft documentation page Application Registration.

The App Paths key in registry hive HKEY_CURRENT_USER usually does not exist as installation is done using trusted installer or local administrator account and therefore the registration of the installed application is done in registry hive HKEY_LOCAL_MACHINE. But on a per user installation of an application the HKCU path is used for application registration instead of HKLM path.

The App Paths key under Wow6432Node key exists only on Windows x64. But x86 applications are registered nevertheless usually in both App Paths although Wow6432Node is for 32-bit applications and the other tree for 64-bit applications on Windows 7 x64, Windows Server 2008 R2 x64 and later Windows x64. For details see Microsoft article Registry Keys Affected by WOW64.

One more note:

Even with .exe specified, start searches in current working directory as well as in directories of PATH after not found AppName.exe additionally for AppName.exe.* and checks file extension (string after last period) against the file extensions in PATHEXT if this returns one or more file names. It is nevertheless always better to specify the file extension of the application to start as a search for AppName.exe is always done first before the wildcard search is executed if AppName.exe could not be found in the current directory.

The free tool Process Monitor of Sysinternals (Microsoft) is a great tool to find out things like that.

Last but not least for none executables start checks also HKEY_CLASSES_ROOT for a file association to open a file or a URI (URL) with associated application defined for command open. That is the reason why something like below also works.

start MyTextFile.txt
start https://stackoverflow.com/

%SystemRoot%System32cmd.exe containing the code for start uses the Windows shell function ShellExecuteEx for executing applications or opening files or URLs with associated application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...