Issue
I want to ask for administrator permissions at runtime in my application, but I couldn't find anything, despite the googling and searching. I could only find posts regarding rights at startup, I found one but, it was valid for .NET Framework, I can't really use dNF, I am using .NET Core 5.
Anyhow, how do I demand it? Maybe call some C functions from Win32 API? My application is Windows only, that's why I mentioned that. (yes, but I still can't port over from .net 5)
Solution
As far as my research (May 9, 2021) when, there is no possible way to extend the privileges of the current program. Also see @Flydog57's comment:
You can't. If you want to get the OS UAC prompt asking the user to use his/her admin mojo when running the program, only the OS can do that for you, and it is done before your code starts. When a program starts, it gets a token that identifies the user and his/her permissions and privileges. When UAC is enabled, an admin user has a non-admin token and an admin token. As a program starts it gets one of those. Once the program starts, the token cannot change. If you need to do this, start up another process with a different token.
The only logical solution is to start a new executable/process whole together with elevated privileges. With C#, you can use System.Diagnostics.Process
.
However, this might change (I have no sources, but it's a possibility) in the future.
Answered By - ANF-Studios Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.