-5

How to request admin rights from a user in golang?

In principle, I know that on the exe program you can check the Run as administrator checkbox in the properties. But I need an example in code form. So that they can be requested not at the start of the program. And somewhere at the end.

kostix
  • 51,517
  • 14
  • 93
  • 176
Fre Over
  • 13
  • 1
  • That's not a question about programming in Go because general-purpose programming languages do not implement any concept of "elevating access rights of a running process". Hence what you're after is a way to ask Windows—the OS—to do that for your process. That's what you have to search the internets for. And then the task of calling out the OS from Go might present a valid programming problem, but before rushing to SO with it, please study the Go's standard library which has lots of examples of how to call out to Win32 API. – kostix Sep 19 '22 at 13:32
  • See [Windows Vista for Developers – Part 4 – User Account Control](https://weblogs.asp.net/kennykerr/Windows-Vista-for-Developers-_1320_-Part-4-_1320_-User-Account-Control) (yes, it's involved, and it literally takes someone outside of Microsoft to explain Microsoft technology). – IInspectable Sep 19 '22 at 14:52

1 Answers1

0

It's not possible for an already-running process to be elevated (or, as far as I know, restricted further). It can be faked by having an already-running process spawn a new elevated process and then communicate with that new process but that only works if you control the code of the program that you wish to have run in a restricted context most o the time but perform some elevated operations.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • The granularity of access control is a thread. I'm convinced that you can set up a thread's tokens so that it runs *"elevated"*. That'd take a pretty deep dive on access control, how it's implemented, and the (undocumented) API's it's exposed through. But the "official" avenues are either activating an elevated COM object, or creating a process through the Shell. – IInspectable Sep 19 '22 at 17:08