Cause a UAC popup from commandline without custom tools

8

3

In Win7, a user can right-click on a program and choose 'Run as administrator'. You get a popup, but do not have to enter the administrator password.

I would like to get the same functionality, but from the commandline - in particular, from inside a .bat file.

I am aware of the built-in runas command, but I have not found a way to use that that doesn't end up asking for a password at some point.

I am also aware of the Process.StartInfo.Verb = "runas"; method, which does exactly what I want, but requires me creating a custom .NET app.

Is there any way, using only built-in commandline tools in Win7, to accomplish this?


Update: Thanks to uSlackr, I worked out this command:

powershell Start-Process cmd.exe -Verb RunAs

Of course, the cmd.exe is just a placeholder.

jwd

Posted 2012-05-03T22:50:26.373

Reputation: 2 652

Answers

4

You can use the Start-Process cmdlet in Powershell with the RunAs verb. More here: http://technet.microsoft.com/en-us/library/dd347667.aspx

uSlackr

Posted 2012-05-03T22:50:26.373

Reputation: 8 755

XP doesn't have UAC so the question is not relevant to it – nponeccop – 2014-12-06T01:20:10.040

@nponeccop I assume the motivation for wanting to run under Windows XP is to let a single script run on both Windows 7 and Windows XP, not have one path for Windows 7 that has PowerShell and UAC and a second path for Windows XP that has no PowerShell and no UAC. – Damian Yerrick – 2018-04-18T13:47:05.950

Perfect, thank you. I updated the question with a working example. – jwd – 2012-05-03T23:56:45.530

Any equivalent on Windows XP? – Maxbester – 2013-06-07T12:31:50.890

Powershell is available for XP. – uSlackr – 2013-06-07T19:19:20.723

1

Simply run the cmd.exe as administrator.

The keyboard shortcut for this is [shift] + [enter] after you have selected the commandline from the start menu. A UAC window should pop up.

OR

Run everything as Admin

Not recommended for everyday usage, but there is also a built in administrator account that you can activate in windows that will simply run any and all applications as root. In an administrative cmd:

net user administrator /active:yes

Change that to '/active:no' if you want to disable the account. A brief intro here.

A. Hayes

Posted 2012-05-03T22:50:26.373

Reputation: 93

Regarding your first suggestion: Sorry, I was not clear. I want to do this from inside a .bat file (question updated). – jwd – 2012-05-03T23:50:06.583

Regarding your second suggestion: I ran this, and got "System error 5 has occurred. Access is denied." – jwd – 2012-05-03T23:50:48.363

Even running cmd.exe as admin? – A. Hayes – 2012-05-04T21:59:24.337

1The whole point of this question is that I am running this command as a non-admin user and I want to temporarily elevate permissions. – jwd – 2012-05-05T01:37:43.223