How to send source path to a button or usercmd start by asterisk?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
dindog
Senior Member
Senior Member
Posts: 315
Joined: 2010-10-18, 07:41 UTC

How to send source path to a button or usercmd start by asterisk?

Post by *dindog »

I added a usercmd *C:\Windows\system32\cmd.exe, but it will not set the path to the source like the unprivileged one, what should I do to send the source path as start path?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: How to send source path to a button or usercmd start by asterisk?

Post by *ghisler(Author) »

This is a known Windows bug, shells started with admin rights always launch in c:\windows\system32

You could send "%P" as one of the parameters, and then use that to change to the correct directory, e.g. with
cd %1
Author of Total Commander
https://www.ghisler.com
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: How to send source path to a button or usercmd start by asterisk?

Post by *Dalai »

ghisler(Author) wrote: 2022-01-14, 15:35 UTCThis is a known Windows bug, shells started with admin rights always launch in c:\windows\system32
According to this answer on StackOverflow it's a security feature:
Microsoft added this as a security feature starting in Windows 8. Whenever cmd.exe detects it's running elevated, it ignores its launch parameters and always starts in %SystemRoot%\System32. You cannot override this behavior.
If you think about it, it makes sense as a security feature. It could help prevent some DLL dropping attacks where a user places some DLL with the same name as known Windows DLLs (like kernel32.dll or shell32.dll or similar) in the same directory as an executable file. Now instead of loading the malicious DLL, the system loads the one from a directory that is known to be safe: the Windows (or system32) directory when the executable is launched elevated (via runas verb).

But there are indications that it started in Vista:
A particularly vexing problem — which the prologue solves — is that in Vista with UAC, if a .BAT file is launched "as Administrator," it doesn't start up in the folder where INSTALL.BAT resides — instead it's usually running in Windows\System32. So one of the steps in the prologue is to get back to the right startup folder.
SS64.com also mentions it:
When a script is run with elevated permissions several aspects of the user environment may change: The current directory, the current TEMP folder and any mapped drives will be disconnected.
(Though I don't agree with the "disconnected" part.)

Anyway, I don't think it's a bug. If it was, MS would have fixed it within the last 14 years, wouldn't they? Yeah sure, there are other long-standing bugs in Windows like the one in wevtutil...

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
petermad
Power Member
Power Member
Posts: 14741
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to send source path to a button or usercmd start by asterisk?

Post by *petermad »

I use this command to start as administrator in current directory:

Code: Select all

[em_ext_cmdelevated]
cmd=*%COMSPEC% /C
param=Start /D"%P"
menu=Command Prompt as Administrator
button=cmd.exe
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
dindog
Senior Member
Senior Member
Posts: 315
Joined: 2010-10-18, 07:41 UTC

Re: How to send source path to a button or usercmd start by asterisk?

Post by *dindog »

petermad wrote: 2022-01-14, 18:16 UTC I use this command to start as administrator in current directory:

Code: Select all

[em_ext_cmdelevated]
cmd=*%COMSPEC% /C
param=Start /D"%P"
menu=Command Prompt as Administrator
button=cmd.exe
thanks. problem solved.
Post Reply