开发者

Run As Administrator if possible, if not: run with limited privileges?

开发者 https://www.devze.com 2023-01-25 09:51 出处:网络
I need to change the behavior of my application depending on user privileges: When my application can run as Administrator

I need to change the behavior of my application depending on user privileges:

  1. When my application can run as Administrator
  2. When my application has limited privileges

Since "requireAdministrator" is embedded within the manifest, the same .exe can't work on (1)开发者_如何学Go and (2) at the same time.

What's the best way to deal with this issue? I am planning to pack two executables (one with "requireAdministrator") and decide which one to run. Someone have other suggestions?


You can use a manifest that asks for highestAvailable instead of requireAdministrator or asInvoker. This will elevate if a person who can just consent to elevating is running it, but won't if it's someone who would need the OTS prompt and entering an admin id and password. I don't care for it myself, since you can't write your code in confidence knowing whether you have the privileges or not. But this is how to achieve what you're asking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号