Start path on buttons not working for elevated process

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Thany
Senior Member
Senior Member
Posts: 292
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

Start path on buttons not working for elevated process

Post by *Thany »

Let's say I want to make a button that starts an elevated command prompt at the current directory. Seems easy enough:

Command: *%comspec%
Parameters: /k
Start Path: %P

Okay, so there's actually three bugs here:

1) The start path is totally ignored, even if I enter D:\, when the command is to be started as an administrator (note the * before the command).

2) The %P variable is not expanded when used in Start Path.

You might think of another way to achieve the same thing, which is to pass the current directory as a cd command, Like so:
Parameters: /k "cd %P"

This is error-prone because of the quotes, and only works for directories on the C drive, because cmd.exe always starts at the user profile, which is usually on the C drive. So for this workaround, bug number three:

3) A variable for the current directory exists, but one for current drive is missing.

These problems lead me to think that achieving a button that starts an elevated command prompt at the current directory, is impossible. Please do corrct me if I'm wrong.

If there's a way to achieve this, please let me know. Otherwise this topic can remain a bug report :)

For reference, all this is tested on TC 9.0a x64 on Windows 10.

/edit

Okay, so this might work:
Parameters: /k "cd /d %P"

But that still leaves it error-prone because of the quotes. And bugs number 1 & 2 remain regardless.
User avatar
HolgerK
Power Member
Power Member
Posts: 5406
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Known issue(since TC 7.56 beta 2):
F1:Dialog box: Configuration - Change button bar wrote:Command: There are many possible commands which can be placed in this field:
1. You may specify the program to be run, including its search path. You can also specify fixed parameters here. Important: You must give the extensions .com and .bat, because by default Windows only finds .exe! With "Change >>" and "Insert file name" you can search for the desired program. Put an asterisk '*' in front of the name to start it with administrative rights, or two '**' to start is as a different user (Windows Vista or newer).
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. It also does not work directly with .bat and .cmd files. Please put cmd.exe /c in front of it.
Regards
Holger
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Re: Start path on buttons not working for elevated process

Post by *DrShark »

2Thany
The issues you described are either features or misfeatures, but not bugs because the behaviour you mentioned described in the help (on the issue #2, help says that special parameters like %P work in Parameters field, but doesn't say that they should work in any other field).
And on your issue with the button, I have a following one that may work for you:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC%
/k cd /d "%P" && @echo off & start /b "%%COMSPEC%%" && exit
%COMSPEC%
Open command prompt window
"%P"
0
-1
all the text after "%P" in parameters line may be removed, I added it to make Microsoft copyrights look the same like when cmd started without /c or /k parameter. I also didn't add the asterisk in the command field (you can add it yourself) because if I need to start the elevated cmd I just use the button's "As Administrator" context menu item.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
Thany
Senior Member
Senior Member
Posts: 292
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

Post by *Thany »

@DrShark
I'm not sure where I should put the code you posted... All I know on the toolbar is the dialog that pops up after selecting "Change..."

@HolgerK
The text you quote is somewhat cryptic. I don't personally understand it to describe my issues. If you believe it does, then good :)
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Post by *gdpr deleted 6 »

Thany wrote:@DrShark
I'm not sure where I should put the code you posted... All I know on the toolbar is the dialog that pops up after selecting "Change..."
Fist, copy the code into the clipboard. Then, in TC, right-click on the toolbar and select "Paste" from the context menu. Voila... ;)
User avatar
tuska
Power Member
Power Member
Posts: 3741
Joined: 2007-05-21, 12:17 UTC

Re: Start path on buttons not working for elevated process

Post by *tuska »

Thany wrote:Let's say I want to make a button that starts an elevated command prompt at the current directory.
These problems lead me to think that achieving a button that starts an elevated command prompt at the current directory, is impossible.

If there's a way to achieve this, please let me know.
For reference, all this is tested on TC 9.0a x64 on Windows 10.
Somewhere I found this code here in the forum:

Code: Select all

TOTALCMD#BAR#DATA
*%SystemRoot%\system32\cmd.exe
/K CD /D "%P"
%COMMANDER_EXE%,2
Admin Prompt  (Administrator!) |Exit from DOS window: exit <ENTER>

0
-1
Regards
Karl

TC 9.0a - 32 bit + 64 bit, Windows 10 Pro (x64) Version 1703 (Build 15063.296)
User avatar
HolgerK
Power Member
Power Member
Posts: 5406
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Thany wrote:@HolgerK
The text you quote is somewhat cryptic. I don't personally understand it to describe my issues. If you believe it does, then good :)
Thany wrote:1) The start path is totally ignored, even if I enter D:\, when the command is to be started as an administrator (note the * before the command).
Help wrote: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.
It doesn't matter what you enter as start path in TC.
The working directory for the elevated program will always be the path of the elevated program.
Even more: any environment variable set by TC is unavailable for the elevated program.
Which means in your case, that e.g. %COMMANDER_PATH% cant' be used inside elevated batches.
Unfortunately a limitation of the windows API.
You may work around the first limitation (for command batches) with the mentioned trick to give a "cd <Path>" to the command processor as parameter, but this will not work if you elevate any other program.

Regards
Holger
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

This is indeed a Windows bug (or missing feature).
Author of Total Commander
https://www.ghisler.com
Thany
Senior Member
Senior Member
Posts: 292
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

Post by *Thany »

Can TC do the proper cd command behind the scenes to work around this supposed Windows bug?
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

Thany wrote:Can TC do the proper cd command behind the scenes to work around this supposed Windows bug?
No, read above again :(
And why don't you use the suggested button ?
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
Post Reply