Pass COMMANDER_* environment vars when running elevated

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Guillaume
Junior Member
Junior Member
Posts: 90
Joined: 2003-04-08, 16:51 UTC

Pass COMMANDER_* environment vars when running elevated

Post by *Guillaume »

TC has the brilliant feature to run programs as Administrator by putting an asterisk in front of the command.

In light of using this with the command

Code: Select all

*%comspec%
I think it would be great if Total Commander could also pass COMMANDER_DRIVE, COMMANDER_EXE, COMMANDER_INSTANCE and
COMMANDER_PATH to this elevated command prompt. Currently, it only does so with non-elevated command prompts, unless TC itself is run as Administrator (which I prefer not to do).
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

Support+++
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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I agree it would be great but I don't sure it is possible. We can't use TCMADMIN for starting elevated tasks because it will omit UAC dialog or show TCMADMIN process in UAC dialog instead of real application, and currently I don't know any way of passing variables through elevation mechanism.
User avatar
Guillaume
Junior Member
Junior Member
Posts: 90
Joined: 2003-04-08, 16:51 UTC

Post by *Guillaume »

Yeah I understand and feared such a thing, too.

It wouldn't be necessary if I could pass these variables inside the Parameters field, though. For instance, if I could pass the TC path so that TC automatically expands that to the actual path, all would be fine. Unfortunately, putting "%commander_path%" in Parameters results in %C expanded + "ommander_path%", while "%%commander_path%%" requires the environment variable.

I suppose it would be a much easier fix to make the environment variables available in the Parameters field between single percentage characters, so that TC first expands them.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Well, if you just need to start cmd.exe, you can pass some envvars in first argument list in the Command field:

Code: Select all

Command: *%COMSPEC% /k "set "COMMANDER_DRIVE=%COMMANDER_DRIVE%" & set "COMMANDER_PATH=%COMMANDER_PATH%"
Parameters: & cd /d %P & set commander"
User avatar
Guillaume
Junior Member
Junior Member
Posts: 90
Joined: 2003-04-08, 16:51 UTC

Post by *Guillaume »

Shoot, I knew I was missing something. I didn't realize in this case that parameters were allowed in the Command field, too... I must've used it sometimes, it's literally in the Help file ("You can also specify fixed parameters here.")

Thanks for bringing this to my attention again! I think I can pretty much realize everything that instigated this topic.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

Here is a workaround:

Make these two commands in your usercmd.ini:

Code: Select all

[em_saveenvironment]
cmd=%COMSPEC% /C set COMMANDER_ > %TEMP%\environment.tmp
iconic=1

[em_openenvironment]
cmd=*%COMSPEC% /C (for /F %i in (%TEMP%\environment.tmp) do set %i)
param=&& Start /D"%P"
Make this button:

Code: Select all

TOTALCMD#BAR#DATA
em_saveenvironment,cm_wait 100,em_openenvironment

%COMSPEC%
Command Prompt as Administrator (with transferred environment)


-1
To make the button:
1. Mark the green text above (including TOTALCMD#BAR#DATA in the first line and -1 in the last line).
2. Copy it to the ClipBoard (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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Guillaume
Junior Member
Junior Member
Posts: 90
Joined: 2003-04-08, 16:51 UTC

Post by *Guillaume »

That oughta work. Thanks! :)
Post Reply