Page 1 of 1

Pass COMMANDER_* environment vars when running elevated

Posted: 2018-04-10, 17:55 UTC
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).

Posted: 2018-04-11, 06:27 UTC
by petermad
Support+++

Posted: 2018-04-11, 07:15 UTC
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.

Posted: 2018-04-11, 14:24 UTC
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.

Posted: 2018-04-12, 08:44 UTC
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"

Posted: 2018-04-12, 16:08 UTC
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.

Posted: 2018-04-12, 17:38 UTC
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".

Posted: 2018-04-17, 00:31 UTC
by Guillaume
That oughta work. Thanks! :)