This forum uses cookies. Click X button to hide this message. What is stored? 
Total Commander Forum Index Total Commander
Forum - Public Discussion and Support
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Start path on buttons not working for elevated process

 
Post new topic   Reply to topic    Total Commander Forum Index -> TC9.0x bug reports (English) Printable version
View previous topic :: View next topic  
Author Message
Thany
Member
Member


Joined: 30 Sep 2003
Posts: 198
Location: Netherlands

PostPosted: Tue May 16, 2017 2:19 pm    Post subject: Start path on buttons not working for elevated process Reply with quote

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 Smile

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.
Back to top
View user's profile Send private message MSN Messenger
HolgerK
Power Member
Power Member


Joined: 26 Jan 2006
Posts: 4588
Location: Europe, Aachen

PostPosted: Tue May 16, 2017 2:31 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
DrShark
Power Member
Power Member


Joined: 03 Nov 2006
Posts: 787
Location: Kyiv, 68/262

PostPosted: Tue May 16, 2017 3:20 pm    Post subject: Re: Start path on buttons not working for elevated process Reply with quote

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:
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.
_________________
Android 4.0.4 w/o root, Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right
Back to top
View user's profile Send private message
Thany
Member
Member


Joined: 30 Sep 2003
Posts: 198
Location: Netherlands

PostPosted: Fri May 19, 2017 9:25 am    Post subject: Reply with quote

@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 Smile
Back to top
View user's profile Send private message MSN Messenger
elgonzo
Senior Member
Senior Member


Joined: 04 Sep 2013
Posts: 253

PostPosted: Fri May 19, 2017 9:33 am    Post subject: Reply with quote

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... Wink
_________________
Windows 7 Pro x64 SP1
Back to top
View user's profile Send private message
tuska
Power Member
Power Member


Joined: 21 May 2007
Posts: 665

PostPosted: Fri May 19, 2017 9:59 am    Post subject: Re: Start path on buttons not working for elevated process Reply with quote

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:
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)
Back to top
View user's profile Send private message
HolgerK
Power Member
Power Member


Joined: 26 Jan 2006
Posts: 4588
Location: Europe, Aachen

PostPosted: Fri May 19, 2017 1:45 pm    Post subject: Reply with quote

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 Smile

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
Back to top
View user's profile Send private message Send e-mail
ghisler(Author)
Site Admin
Site Admin


Joined: 04 Feb 2003
Posts: 33621
Location: Switzerland

PostPosted: Mon May 22, 2017 5:28 am    Post subject: Reply with quote

This is indeed a Windows bug (or missing feature).
_________________
Author of Total Commander
http://www.ghisler.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> TC9.0x bug reports (English) All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Impressum: This site is maintained by Ghisler Software GmbH

Using phpBB © 2001-2005 phpBB Group