Start path on buttons not working for elevated process
Moderators: white, Hacker, petermad, Stefan2
Start path on buttons not working for elevated process
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.
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.
Known issue(since TC 7.56 beta 2):
Holger
RegardsF1: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.
Holger
Re: Start path on buttons not working for elevated process
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:
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.
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
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
Ukraine's National Bank special bank account:
UA843000010000000047330992708
-
- Power Member
- Posts: 872
- Joined: 2013-09-04, 14:07 UTC
Re: Start path on buttons not working for elevated process
Somewhere I found this code here in the forum: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.
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
Karl
TC 9.0a - 32 bit + 64 bit, Windows 10 Pro (x64) Version 1703 (Build 15063.296)
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).
It doesn't matter what you enter as start path in TC.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.
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
- ghisler(Author)
- Site Admin
- Posts: 48232
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
This is indeed a Windows bug (or missing feature).
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
No, read above againThany wrote:Can TC do the proper cd command behind the scenes to work around this supposed Windows bug?
And why don't you use the suggested button ?
Windows 11 Home x64 Version 23H2 (OS Build 22631.3737)
TC 11.03 x64 / x86
Everything 1.5.0.1382a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.78
QAP 11.6.3.3 x64
TC 11.03 x64 / x86
Everything 1.5.0.1382a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.78
QAP 11.6.3.3 x64