Page 1 of 1

Internal variable for current directory

Posted: 2019-10-24, 17:09 UTC
by Slavic
This option can help users who need to run the programs in the elevated mode (As Administrator). Currently TC has a limitation:
Warning: Programs run as administrator will always start with the program directory as the start path, and environment variables (like %COMMANDER_PATH%) are NOT inherited from Total Commander, only those from the system.
For command processor CMD.exe this limitation (running from %windir%\system32) can be partially solved by using the special command line:

Code: Select all

%comspec% /k cd /d %userprofile%
This allows to run %comspec% with additional parameters, which change the starting directory to %userprofile% right upon start. So, CMD runs in %userprofile% directory, which in many cases is better than system32, but not yet always perfect.

I suppose that a special internal variable, resolved on-the-fly by TC before sending the command line to OS, could solve this problem completely.
Imagine, TC can define the internal variable, say, %COMMANDER_CURDIR% and we use it in the command line for CMD button:

Code: Select all

%comspec% /k cd /d %COMMANDER_CURDIR%
We navigate to a particular directory, like C:\Program Files\Tools and call the command prompt as Admin right-clicking on the CMD button. This command is translated to %comspec% /k cd /d "C:\Program Files\Tools" and CMD opens its window in this location in Administrator mode.

Of course, this will work in user mode as well, like it is already implemented in TC by default.

Re: Internal variable for current directory

Posted: 2019-10-24, 17:47 UTC
by petermad
You can do that already with an external command like this:

Code: Select all

[em_cmdelevated]
cmd=*%COMSPEC% /C
param=Start /D"%P"
menu=Command Prompt as Administrator
button=cmd.exe
Or as a button:

Code: Select all

TOTALCMD#BAR#DATA
*%COMSPEC% /C
Start /D"%P"
cmd.exe
Command Prompt as Administrator

0
-1
To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".

Re: Internal variable for current directory

Posted: 2019-10-24, 20:24 UTC
by Slavic
Thanks, it's easy when you know what to do :-)
Indeed, you suggested a two-step procedure of starting CMD which I managed to simplify to one step:

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /k
cd /d "%P"
cmd.exe
Command prompt


-1
Here the CMD can be run in both user and Admin modes without starting new window. Results were checked in Process Explorer, command line is perfect, no mention about non-existent process.
Now I think that such method is deserved to be noticed in the Help system in addition to existing cited info.

Thanks again!