Pass COMMANDER_* environment vars when running elevated

Here you can propose new features, make suggestions etc.

Moderators: Hacker, Stefan2, white, sheep

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

Pass COMMANDER_* environment vars when running elevated

Post by *Guillaume » 2018-04-10, 17:55 UTC

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: 8009
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Post by *petermad » 2018-04-11, 06:27 UTC

Support+++
License #524
Danish Total Commander Translator
TC 9.21a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 64bit and TC 2.91b4 on Android 6.0
Get Extended Total Commander Menus | PHSM-Calendar

User avatar
MVV
Power Member
Power Member
Posts: 8109
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2018-04-11, 07:15 UTC

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: 78
Joined: 2003-04-08, 16:51 UTC
Contact:

Post by *Guillaume » 2018-04-11, 14:24 UTC

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: 8109
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2018-04-12, 08:44 UTC

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: 78
Joined: 2003-04-08, 16:51 UTC
Contact:

Post by *Guillaume » 2018-04-12, 16:08 UTC

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: 8009
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Post by *petermad » 2018-04-12, 17:38 UTC

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
Danish Total Commander Translator
TC 9.21a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 64bit and TC 2.91b4 on Android 6.0
Get Extended Total Commander Menus | PHSM-Calendar

User avatar
Guillaume
Junior Member
Junior Member
Posts: 78
Joined: 2003-04-08, 16:51 UTC
Contact:

Post by *Guillaume » 2018-04-17, 00:31 UTC

That oughta work. Thanks! :)

Post Reply