How can i run program under cursor as admin?

English support forum

Moderators: white, Hacker, petermad, Stefan2

KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

How can i run program under cursor as admin?

Post by *KozakMak »

I know about the method from the context menu. But I want to do it with a hotkey.
OS: Win10 | TC: latest x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How can i run program under cursor as admin?

Post by *petermad »

Put this in your usercmd.ini file(located in the same place as your wincmd.ini):

Code: Select all

[em_startelevated]
cmd=*%COMSPEC% /C
param=start "" %P%N
menu=Open file under cursor as Admin
iconic=1
If the file does not exist, just make it in a text editor.

Put for example this in the [Shortcuts] section of your wincmd.ini file:

Code: Select all

C+ENTER=em_startelevated
If the section [Shortcuts] doesn't exist, just make it.

Then you can open files under the cursor by pressing Ctrl+Enter.

If you dont know where your wincmd.ini is located look in TC's menu at Help -> About Total Commander.
Last edited by petermad on 2022-08-23, 07:54 UTC, edited 1 time in total.
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
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

nice!
this also work with .bat file?
without flashing cmd-window can be done?
OS: Win10 | TC: latest x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How can i run program under cursor as admin?

Post by *petermad »

this also work with .bat file?
without flashing cmd-window can be done?
Then use this:

Code: Select all

[em_startelevated]
cmd=*%COMSPEC% /C
param=if %E==bat (%P%N) else if %E==cmd (%P%N) else start "" %P%N
menu=Open file under cursor as Admin
iconic=1
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
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

when i run .bat (for example only with pause command) cmd-window starts minimized

10.51 rc2 x64

and i use hotkey CAS+ENTER=em_startelevated
OS: Win10 | TC: latest x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How can i run program under cursor as admin?

Post by *petermad »

when i run .bat (for example only with pause command) cmd-window starts minimized
Then use:

Code: Select all

iconic=0
but then you will se a short flash of a DOS console when you use the shortcut for other file types.
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
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

petermad wrote: 2022-08-23, 10:44 UTC but then you will se a short flash of a DOS console when you use the shortcut for other file types.
is there a way to add nircmd?

something like:

Code: Select all

cmd=*nircmd64.exe
param=exec hide cmd if %E==bat (%P%N) else if %E==cmd (%P%N) else if %E==ps1 (start powershell -ExecutionPolicy Bypass -NoExit -File %P%N) else start "" %P%N
OS: Win10 | TC: latest x64
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: How can i run program under cursor as admin?

Post by *Fla$her »

2KozakMak
It 's easier this way:
Fla$her wrote: 2023-01-05, 08:23 UTCSet AlwaysAsAdmin=1 for the [Configuration] section and run TC with elevated rights from URL shortcut.
But if not everything needs to be run with elevating (which is doubtful), then the solution is:
Command: *%WinDir%\System32\rundll32.exe url.dll,OpenURL
Parameters: %P%N

Personally, I also use an environment variable instead of this line, which sets it in autorun.cfg if the Windows version is higher than XP.
Overquoting is evil! 👎
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

and what about .ps1?
Fla$her wrote: 2023-02-20, 09:55 UTC use an environment variable instead of this line, which sets it in autorun.cfg if the Windows version is higher than XP.
example?
OS: Win10 | TC: latest x64
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: How can i run program under cursor as admin?

Post by *Fla$her »

For .ps1 I use the internal associations settings:
Type name: *.ps1
Open: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -nol -noni -nop -ex Bypass -f "%1"
KozakMak wrote: 2023-02-20, 10:57 UTCexample?

Code: Select all

LoadLibrary Plugins\Autorun_Sysinfo.dll

StrMid OSVer %SYSINFO_OSVERSION% 5
If OSVer = 2000 Or OSVer = 'XP' Or OSVer = 2003 Or OSVer = '2003R2' Then
  SetEnv ADM
Else
  SetEnv /EV- ADM '*%WinDir%\System32\rundll32.exe url.dll,OpenURL '
EndIf
Then, in the button or user command, we substitute %ADM% in front:
%ADM%"%COMMANDER_PATH%\Programs\Program.exe"
%ADM%"%COMMANDER_PATH%\Files\File.ext"

But in any case, the first option with ini is better, since it takes into account internal associations.
Overquoting is evil! 👎
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

Fla$her wrote: 2023-02-20, 11:38 UTC For .ps1 I use the internal associations settings:
I need it all to be in one command, so I asked about nir
OS: Win10 | TC: latest x64
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: How can i run program under cursor as admin?

Post by *Fla$her »

2KozakMak
With .ps1 these tricks don't work (it's necessary to change the settings in the registry). And why open files with a hotkey at all, if there is Enter?
Overquoting is evil! 👎
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

Ctrl+Alt+Shift+Enter

Code: Select all

[em_startelevated]
cmd=*%COMSPEC% /C
param=if %E==bat (%P%N) else if %E==cmd (%P%N) else if %E==ps1 (start powershell -ExecutionPolicy Bypass -NoExit -File %P%N) else start "" %P%N
OS: Win10 | TC: latest x64
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: How can i run program under cursor as admin?

Post by *Fla$her »

Ah, I didn't pay attention to ps1 check.
Command: *%COMMANDER_PATH%\Utils\NirCmd\nircmd.exe execmd
Parameters: "(if /i "%E"=="bat" (%V) else if /i "%E"=="cmd" (%V) else if /i "%E"=="ps1" (powershell.exe -nol -noni -nop -ex Bypass -f %V) else start "" %V)&"~$nir.exefile$" win postmsg foreground 1075 540"

However, this does not cancel my question about Enter.
Last edited by Fla$her on 2023-02-20, 15:34 UTC, edited 1 time in total.
Overquoting is evil! 👎
KozakMak
Senior Member
Senior Member
Posts: 352
Joined: 2021-05-24, 12:39 UTC
Location: UA

Re: How can i run program under cursor as admin?

Post by *KozakMak »

exe - ok
bat - do nothing
ps1 - open in notepad

¯\_(ツ)_/¯
OS: Win10 | TC: latest x64
Post Reply