Elevate a running program to administrator (Windows 7)

35

6

Sometimes you may open a program that you want to run as an administrator, but you may already have opened it not as an administrator. Is it possible to elevate the privileges of an already running program in Windows 7 or do I have to close and restart as admin?

Casebash

Posted 2010-04-09T02:28:34.223

Reputation: 5 677

8sudo for the win! – Josh K – 2010-04-09T02:57:42.993

1@Josh K - er - How can you elevate an already running app using sudo ? – Sathyajith Bhat – 2010-04-09T03:30:52.087

It's magical, you'd have to decode man sudo for more information. – Josh K – 2010-04-09T03:58:53.543

2@Josh, if nothing else, you can always use pseudo ;) – Tomas Aschan – 2010-07-16T22:44:04.937

1Is there any 'sudo' command for Windows? – phuclv – 2017-06-04T15:45:09.437

Answers

26

Unfortunately, no. A running process cannot be elevated to administrator privileges. I'm looking for a more authoritative source, but for now I have found:

  1. "Programs can't be elevated once they've already been launched..."

  2. "Code can only be elevated at process level when startup, which means that a running process cannot be elevated."

Stephen Jennings

Posted 2010-04-09T02:28:34.223

Reputation: 21 788

1

This is absolutely untrue. The win32 API does support elevation of arbitrary applications that are already running, though the application in question must expose the functionality itself. This article and accompanying source code demonstrate how to accomplish this. It is conceivably possible that one could write an application to select and elevate other processes...

– Fopedush – 2013-12-23T19:13:05.307

8@Fopedush Although that article describes this technique as "self-elevating", what those example programs seem to actually be doing is launching a new instance of the process using ShellExecuteEx and the verb "runas". I don't think that achieves the OP's need to elevate a program that's already running (it will lose all of its state, for example). – Stephen Jennings – 2013-12-23T23:47:44.983

when a non-elevated Total Commander 8.01 instance is blocked in an operation such as copying into a program files subfolder, it offers the possibility to "retry as administrator". Cannot this be extended to "foreign" (not self) processes? – n611x007 – 2013-12-27T17:18:20.350

3@naxa I haven't used Total Commander, but I'd be willing to bet the "retry as administrator" option actually spawns a completely separate elevated process which performs the privileged work. Process Explorer does this when you choose "Show details for all processes", it launches a new elevated copy of itself and closes the unelevated copy. If that's the case, then programs need to be specifically written to know how to launch the second process correctly. – Stephen Jennings – 2013-12-27T19:49:37.883

1@StephenJennings You're completely right - the code sample I linked does in fact just relaunch with the runas command. I should have vetted the code in addition to the article before commenting. I had been under the impression that the WIN32 api did expose some kind of elevation mechanism - but perhaps I'm misremembering. I'll dig around and post again if I can find what I was thinking of. – Fopedush – 2013-12-31T18:09:08.807