1

I'd like to add an action on Context menu when right-clicking on a Directory in the Windows File Explorer.

enter image description here

This works:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\test\command] @=""C:\Python311\pythonw.exe" "D:\test\test.py" "%1""

[HKEY_CLASSES_ROOT\Directory\Background\shell\test\command] @=""C:\Python311\pythonw.exe" "D:\test\test.py" "%v""

but how to make it start as administrator instead?

I've tried:

  • runas /user:administrator ... without success because I don't use a password for current user, and it seems to require a password

  • @="powershell -WindowStyle Hidden -Command \"Start-Process 'C:\\Python311\\pythonw.exe' -ArgumentList 'D:\\test\\test.py','%1' -Verb runAs\"" but this shows a PowerShell window for a few seconds which I don't want

  • adding HasLUAShield registry entry

  • there seem to be options with a VBS launcher but I'd like to avoid another language like VBS

without any success.

I cannot make it work, is it maybe linked to this: 1809 update broke "run as administrator" from context menus only on desktop and start menu?

Which trick do all tools that get started as admin, from context menu? I think it should be common.

NB: it works if we explicitely name it runas:

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="test"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command] @=""C:\Python311\pythonw.exe" "D:\test\test.py" "%1""

but then this means that we would not be able do it for a second context menu action, because there is just one runas, see Multiple context menu run as administrator through registry editor.

Basj
  • 2,143

1 Answers1

0

As mentioned by @Cpt.Whale, the answer is to do the elevation in the target program itself, rather than in the Windows Explorer context menu.

(This can be done in various languages, such as with this in Python).


Remark about:

it works if we explicitely name it runas:
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
but then this means that we would not be able do it for a second context menu action, because there is just one runas

See main answer of How do I change "Open with Powershell" to "Open with Command Prompt" when shift-rightclicking in Explorer?, they use sub-menus (Command Prompts, PowerShell Prompts) to have multiple runas keys that automatically trigger elevation.

Basj
  • 2,143