PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

Apps run with Keyboard Manager do not respect the selected elevation mode when running PowerToys in administrator

Open jackharro opened this issue 1 year ago • 23 comments

Microsoft PowerToys version

0.79.0, 0.80.0

Installation method

PowerToys auto-update

Running as admin

Yes

Area(s) with issue?

Keyboard Manager

Steps to reproduce

I'll put details in brackets

  1. Start PowerToys in Administrator (Always run as adminstrator)
  2. Remap a chord to start an app (Win + T to start Windows Terminal)
  • You can follow KBM → Remap a shortcut → Win + T → Action: Run Program → Select Program → type wt in the directory field, close the terminal window, and copy and paste the directory field contents to the file name field)
  1. Set the elevation to normal
  2. Save the confuration, hit Win + T, and find that the command prompt is in administrator mode

✔️ Expected Behavior

Windows Terminal, the app opened by a remapped shortcut, is opened with normal privileges

❌ Actual Behavior

Windows Terminal, the app opened by a remapped shortcut, is opened with adminstrator privileges

Other Software

Windows Terminal 1.19.10821.0 Windows 10 22H2 build 19045.4170 UAC Settings is set to Never Notify (i.e. skip administrator password entry)

jackharro avatar Apr 03 '24 13:04 jackharro

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Apr 03 '24 13:04 github-actions[bot]

@jacko-png Can you please upload some screenshots and a /bugreport. This would be very helpful.

htcfreek avatar Apr 03 '24 15:04 htcfreek

https://github.com/microsoft/PowerToys/assets/114323964/092d4218-9aae-4d82-9e46-91c9f9485cbc

ghost avatar Apr 04 '24 01:04 ghost

I can reproduce this issue too. Pretty annoying and unsafe. I didn't realize but I've been using admin mode to run different shell scripts for weeks now :(

image

https://github.com/microsoft/PowerToys/assets/69104500/655ec874-47dd-42b4-9407-fa9cc4d7fa71

Curstantine avatar Apr 04 '24 03:04 Curstantine

@jacko-png The run as administrator problem is logical for me even if isn't what users are expecting. It should be reworked.

But you wrote something about a wrong working directory. And I don't understand exactly how this problem behaves. Can you post a screenshot for this too please.

htcfreek avatar Apr 04 '24 06:04 htcfreek

<removed to keep the scrolling clean, I had screenshots and a description of the working directory issue which is separate>

ghost avatar Apr 05 '24 13:04 ghost

@jacko-png Regarding the wt issue I suggest you to check the wt documentation. I imagine that they have a working dir parameter.

htcfreek avatar Apr 05 '24 13:04 htcfreek

Yes, the -d option does this. It's not listed in the --help page, however, so I had to find it on MSDN. For any future commenters, let's return this thread to the elevation issue.

ghost avatar Apr 05 '24 13:04 ghost

Yes, the -d option does this. It's not listed in the --help page, however, so I had to find it on MSDN. For any future commenters, let's return this thread to the elevation issue.

Can you please update the issue description to only describe the elevation issue and add a note that the folder thing is caused by wt. Currently tytle and description are different and this is confusing.

htcfreek avatar Apr 05 '24 15:04 htcfreek

Good idea 👍. I was thinking of ways to clean it up and forgot I could edit.

ghost avatar Apr 05 '24 23:04 ghost

I have been contemplating a potential enhancement or feature request regarding the search functionality. Currently, when searching for the Command Prompt (Alt+Tab), there is no apparent option to launch it with administrative privileges directly from the search results. I would like to propose the ability to right-click or use an alternative mechanism within the search results to open the Command Prompt in Administrator mode. This would streamline the process of executing commands that require elevated permissions without the need for additional steps.

Feejus avatar Apr 07 '24 19:04 Feejus

@Feejus You could map something like Shift+Win+T to Command Prompt and set it to run in administrator mode. That works just fine, the issue here is that we can't run it in normal mode if PowerToys is run in administrator, which I may or may not need to have to do at some point.

Does your feature request relate to this issue, which is about administrator PowerToys not starting programs in normal mode?

ghost avatar Apr 07 '24 20:04 ghost

@jacko-png

As to your question, I am afraid no.

When I press "Alt+Space" with PowerToys running, and search for CMD or Terminal, the search results allow me to open these applications. However, when I launch them through this method, they start in a regular user session, without elevated administrative privileges.

If I search in the Start menu I see an option to run CMD as administrator, the alternative is to right-click the search and I get a menu which has "run as admin".

Thanx

Feejus avatar Apr 08 '24 01:04 Feejus

As to your question, I am afraid no.

You're in the wrong thread. This is a bug, and that's a feature request. You're talking about Power Toys Run, and we're talking about Keyboard Manager.

By the way, press Ctrl + Shift + Enter next time you try. Should be able to run an administrator command prompt from PowerToys Run.

ghost avatar Apr 08 '24 02:04 ghost

@jacko-png Can you please upload some screenshots and a /bugreport. This would be very helpful.

@htcfreek Wait did the bug report not upload? I'll try again.

ghost avatar Apr 08 '24 02:04 ghost

@jacko-png The run as administrator problem is logical for me even if isn't what users are expecting. It should be reworked.

For example, PowerToys Run launches software in normal mode unless you hold Ctrl + Shift, even in administrator mode.

https://github.com/microsoft/PowerToys/assets/114323964/93624fd9-8cc5-4d7b-9e24-1edc85382553

The video shows a normal command prompt and that PowerToys is running as administrator.

ghost avatar Apr 08 '24 02:04 ghost

As to your question, I am afraid no.

You're in the wrong thread. This is a bug, and that's a feature request. You're talking about Power Toys Run, and we're talking about Keyboard Manager.

By the way, press Ctrl + Shift + Enter next time you try. Should be able to run an administrator command prompt from PowerToys Run.

Thanx for clarification. I very much appreciate it. The reason I did not raise it as FR is that this would work equally as well for me. I.E if the Powertoys is running in Admin and I run CMD, it should run it with admin privileges.

Feejus avatar Apr 08 '24 07:04 Feejus

In my tests, I noticed that this bug also happens with other UWP apps (like Notepad), but it doesn't happen with desktop apps (like Excel, Photoshop, cmd etc). It would be great if anyone else can test it and let us know.

You can check if an app is running elevated with the Task Manager (go to the Details tab > Right click the column names > Select columns > Check Elevated).

ThiagoRangel7 avatar Apr 10 '24 01:04 ThiagoRangel7

@jaimecbernardo Hot fix possible?

htcfreek avatar Apr 10 '24 06:04 htcfreek

So this is a bug? I'd figured it might have just been a natural consequence of how Windows works, considering how any process opened out of an elevated terminal will be elevated as well, but that it doesn't occur with native apps does suggest otherwise...

AdreKiseque avatar Jan 08 '25 18:01 AdreKiseque

Any chance we can get some priority on this? It's a rather troublesome bug... In the meantime, I have a workaround for anyone suffering it, though it's not perfect. You can set your shortcut to open Explorer with the target executable as an argument, which will launch it through Explorer and thus unelevated. Caveat is you can't add any extra arguments to it (but you can work around this too by creating a shortcut that launches your desired app with its arguments, then opening that with Explorer... ridiculous as that gets). Just make sure you set KBM to open a new instance "if" Explorer is already running (which it is).

AdreKiseque avatar Jan 16 '25 22:01 AdreKiseque

In the meantime, I have a workaround for anyone suffering it, though it's not perfect. You can set your shortcut to open Explorer with the target executable as an argument, which will launch it through Explorer and thus unelevated. Caveat is you can't add any extra arguments to it (but you can work around this too by creating a shortcut that launches your desired app with its arguments, then opening that with Explorer... ridiculous as that gets).

Somehow this is the canonical way of doing it: https://devblogs.microsoft.com/oldnewthing/20131118-00/?p=2643

I am not familiar with how PowerToys spawn processes, but this could be done.

takase1121 avatar May 04 '25 01:05 takase1121

Would love to see an update on this. I'm still facing this issue on 0.94.2 It causes firefox.exe to not launch correctly and windows terminal to always treat powershell as admin instead of a normal user

IamSmeagol avatar Oct 12 '25 19:10 IamSmeagol

Update: @IamSmeagol I am not sure when but "Elevation" seems to work when running PowerToys in admin mode. This screenshot is from 0.95.0 and I am not getting elavation prompt.

@ghost could you confirm bug is fixed.

Image

TekBear avatar Oct 20 '25 08:10 TekBear

@TekBear I just tested it myself and it's still broken it seems. Even if you have the elevation setting in the shortcut set to normal, it'll still run as admin if PowerToys itself is elevated. Same issue that's always been. I'm on 0.95.0 as well.

AdreKiseque avatar Oct 20 '25 18:10 AdreKiseque

I tested with cmd.exe and it works. I am logged in as normal user, Win 11 Ent 23H2, Powertoys is running with setting "restart powertoys as administrator", I get an elevation prompt when shortcut is set to "elevated". As shown:

Image

@AdreKiseque ok so not fixed for everyone. Do you get same result for cmd.exe?

TekBear avatar Oct 22 '25 03:10 TekBear

Do you get same result for cmd.exe?

@TekBear Having this problem for a long time. cmd.exe works. However, wt.exe (windows terminal) does not launch properly. It's always elevated and I don't know how this happens. By the way, many apps crashes when launched by this feature (like Visual Studio and Code) so I'm not able to test other apps for now.

SamHou0 avatar Oct 22 '25 07:10 SamHou0

@TekBear It works for cmd, yes, as well as powershell and pwsh. The issue is relegated to UWP apps it seems, something actually brought up earlier in this thread (though I confess I had forgotten so myself until the familiarity of the situation prompted me to scroll up). To note is all the shells launched like this opened in the old conhost.exe rather than Windows Terminal, despite that not being the case when launched from the run dialogue.

AdreKiseque avatar Oct 22 '25 16:10 AdreKiseque

@AdreKiseque, yes I had miss that UWP app caveat thanks for pointing that out.

I have updated to v0.95.1 and manually restart Keyboard Manager as normal user to get it to start shortcuts in user mode this seems to work best for me using non-UWP apps.

TekBear avatar Oct 29 '25 00:10 TekBear