PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] How to request administrator permissions at runtime?

 October 19, 2022     admin, c#, runtime     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing