Internal variable for current directory

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Slavic
Senior Member
Senior Member
Posts: 290
Joined: 2006-02-26, 15:41 UTC
Location: Montenegro

Internal variable for current directory

Post 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.
Desktop: Windows 11 Pro 23H2, TC 11.03(RC). Mobile: Pixel 5a, Android 14, TC 3.42b5
User avatar
petermad
Power Member
Power Member
Posts: 14795
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Internal variable for current directory

Post 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".
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Slavic
Senior Member
Senior Member
Posts: 290
Joined: 2006-02-26, 15:41 UTC
Location: Montenegro

Re: Internal variable for current directory

Post 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!
Desktop: Windows 11 Pro 23H2, TC 11.03(RC). Mobile: Pixel 5a, Android 14, TC 3.42b5
Post Reply