Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

If I am not able to right click on CMD and run as administrator, or CTRL + Shift + Enter to run CMD, but I am using an administrative user account in a non-admin shell (CMD.exe); How in the world do I escalate to an admin from that shell?

Runas does not seem to have a switch for escalation. Assume I do not know the password for the user called Administrator. I am just a normal user in the Administrators group.

Preferably without using some 3rd party app, but I will take what I can get.

share|improve this question

marked as duplicate by Greg Askew, Falcon Momot, Ward, Jenny D, Michael Hampton May 25 '13 at 17:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

In what situation would you be able to launch a command prompt, but not run it as administrator through a keystroke combo or right-click > run as administrator? What problem are you trying to solve here?? – MDMarra May 24 '13 at 18:45
I assume you mean be able to launch a cmd prompt, but not able to run it as administrator. I am using TeamCity to perform software builds. The server runs on a Tomcat/MSSQL/IIS Windows Server 2008 R2, and the agents are numerous Win 7 and Linux workstations. The build processes are configured on the server and they interact with a remote windows file server, and shares on the build server itself. I am running a del command from a win 7 agent, to delete stuff on a share on the build server, and need to escalate if there is a failure, so that I can run handle.exe to catch what locked my file – user160910 May 24 '13 at 18:51
In other words the server is performing a bunch of steps, either running executables, or cmd line arguments, and I am not performing keystrokes or mouse movements. – user160910 May 24 '13 at 18:52
up vote 3 down vote accepted

You can't, natively, using just Cmd.exe. Cmd.exe is from an ancient time long before things like "privilege escalation" were ever contemplated in Windows.

Here, have some VBscript.

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\Windows\System32\cmd.exe", "", "", "runas", 1

That "Runas" verb is the trick.

However, If you want to not get prompted by UAC, then you need to turn off UAC.

Maybe you could do something hackish like use schtasks.exe to add a scheduled task that runs your script as System.

This article is relevant:

share|improve this answer
I am aware of VBscript, but I prefer to do it from CMD.exe natively. I don't know why they didnt add an escalate to admin token switch to runas. I'll accept this answer. – user160910 May 25 '13 at 15:49