0

As the title says I'm searching for a way to ask for admin privileges on runtime. I'm currently working on a game launcher and I was wondering how launchers like Steam or Epic Games only ask for permission when you need to install a game. Thanks for help

Inkling00
  • 13
  • 5
  • Does this answer your question? [How to force a WPF application to run in Administrator mode](https://stackoverflow.com/questions/5276674/how-to-force-a-wpf-application-to-run-in-administrator-mode) – Ryan Wilson May 20 '22 at 18:31
  • I already did it, but what I need is to display the dialogue while the application is running, like epic games launcher does. – Inkling00 May 21 '22 at 07:53

1 Answers1

-1

As far as I'm concerned you are trying to display UAC prompt that will ask for admin privileges. If that is the case you have to add an application manifest. This will show the UAC prompt automatically.

You can see here how to set it up

kddinev18
  • 76
  • 4
  • Yes, but it will show the UAC on start. I need it on runtime, when a button is pressed, because I only need it when I access Program files. – Inkling00 May 22 '22 at 11:55
  • Then maybe start a new process that has admin privileges and execute the code using this process – kddinev18 May 22 '22 at 12:35
  • Then how do game launchers ask for permission only when they have to? – Inkling00 May 24 '22 at 16:32
  • Based on my research this is done automatically by the operating system. When the thread that is running the code has to do smth that requires elevated privileges the UAC prompt show automatically. But I'm not 100% sure about this – kddinev18 May 24 '22 at 19:49
  • I tried it, but it keeps freezing. – Inkling00 May 29 '22 at 09:06