Finding the paths of Total Commander files

From TotalcmdWiki
Jump to navigation Jump to search

Note: Please don't edit the text, correct the typos only. If you have comments, write them to the Discussion page.


Introduction

This small article is written for clarification of the topic about finding the Total Commander files' locations. There is already small similar article about this in Russian by SAM, which misses several finding steps. I'll try to mention all possible cases of TC files location, either by using registry or by using ini files.

We have 3 "variables" regarding Total Commander, which may be useful:

  • Path of Total Commander folder. If you need the path of executable, just add the '\Totalcmd.exe' string to the folder path. See the note below.
  • Path of main config file (its default name is wincmd.ini).
  • Path of FTP config file (its default name is wcx_ftp.ini).

Below are step-by-step algorithms of finding these paths.


Finding the TC folder path

1) Look for the %COMMANDER_PATH% environment variable value. If this variable is set, this is the result. Overwise go to next step.

When our program is run from TC (versions 6.00 and newer), this variable will ALWAYS be set; so if we will write in our Readme that the program must be run from TC, this 1st step will be enough.

2) Look for the registry key value:

HKEY_CURRENT_USER\Software\Ghisler\Total Commander\InstallDir

If it's not empty, this is the result. Overwise go to next step.

3) Look for the registry key value:

HKEY_LOCAL_MACHINE\Software\Ghisler\Total Commander\InstallDir

If we found the TC folder path, we should check its "validity":

  • check the existance of file "Totalcmd.exe" in this path,
  • also OPTIONALLY check that "Totalcmd.exe" file has the value 'TOTALCMD' in the 'InternalName' field of its VersionInfo structure.

We should save the resulting path, we'll need it later.

If the path was not found (this may be when Total Commander was installed by hands), we still can try to find other paths, but we'll have to skip several algorithms steps which rely on TC folder path.

Finding the TC main config file

1) Look for the %COMMANDER_INI% environment variable value. If this variable is set, this is the result. Overwise go to next step.

When our program is run from TC (versions 6.55 and newer), this variable will ALWAYS be set.

2) OPTIONAL step. We can try to find the config file name **from the command line of currently opened Total Commander process**. Note that this is the very exotic way, and I don't recommend to use it unless you really need it in your application. As far as I know, the only application that uses this way is the ReloadTC.

3) OPTIONAL step. If we found the TC folder path before, we should support the following TC feature (for versions 6.50 and newer): if the file "wincmd.ini" is present in the TC folder, it can contain the key "UseIniInProgramDir", which tells that config file is actually placed in the TC folder. See the TC help for the possible values of this ini key.

4) Look for the registry key value:

HKEY_CURRENT_USER\Software\Ghisler\Total Commander\IniFileName

If it's not empty, this is the result. Overwise go to next step.

5) Look for the registry key value:

HKEY_LOCAL_MACHINE\Software\Ghisler\Total Commander\IniFileName

If it's not empty, this is the result. Overwise go to next step.

6) Finally take the default config file name, which is:

  • in Windows Vista and other systems, which have their Windows folder read-only:
%AppData%\Ghisler\wincmd.ini
  • in other systems:
%Windir%\wincmd.ini
 Quote from the TC History.txt file:
 14.06.06  Added: Installer: Set default location of ini files
 to %APPDATA%\GHISLER on NT/2000/XP if the Windows directory is not writable
 (for non-admin accounts)
 11.06.06  Added: Installer: Set default location of ini files
 to %APPDATA%\GHISLER on Windows Vista if there was no user-defined location
 set


Finding the TC FTP config file

We perform the same steps that are listed above for the main config file, with exceptions:

  • The 1st step with environment variable is skipped. We don't have an environment variable, which is responsible for the FTP config location.
  • Registry keys names are different:
HKEY_CURRENT_USER\Software\Ghisler\Total Commander\FtpIniName
HKEY_LOCAL_MACHINE\Software\Ghisler\Total Commander\FtpIniName
  • On the last step, with default config name, we take files in the same folders but with different name: not "wincmd.ini" but "wcx_ftp.ini".


Notes about registry keys values

1) In the keys, which hold the paths to config files, we can find both absolute and relative paths. In the case when config files are placed into TC folder using the IniReloc utility, we can have registry keys values in the form ".\file_name", with the dot instead of path. We must interpret this "dot" as TC folder path.

If the TC folder path was not found before, we cannot expand the relative paths and should skip the corresponding algorithm step.

2) In the registry keys the environment variables can be used, for example: "%AppData%\Ghisler\wincmd.ini".

If we cannot expand these variables (using ExpandEnvironmentStrings), we should skip the corresponding algorithm step.

3) IniReloc utility saves registry keys under HKEY_CURRENT_USER when saving settings only for a current systems user. And it saves keys under HKEY_LOCAL_MACHINE when saving settings for all users on system.

General notes

1) We assume that TC executable has the name "Totalcmd.exe". If it's not so (user has renamed the file), then it will be hard to find the executable. I recommend to assume the "Totalcmd.exe" name. But if you need to find the renamed executable, just enumerate all *.exe files in found TC folder, and take the 1st one which has the 'TOTALCMD' value in the 'InternalName' field of VersionInfo structure.

2) This text is applicable to external utilities only. Plugins should normally NOT worry at all about these paths, but use the DefaultIniName file (or location with different file name) from the *SetDefaultParams API function instead. Why? The plugin may be called by a third party program like Universal Viewer or other tool, not by Total Commander itself!



Alexey Torgashin; 2007


Back to Developer's corner