How to run a program with admin privilege

6

2

I need to run a program as a different user + make it run with admin privileges (Run as administrator).

I use the 'runas' for running the program as a different user

How can I run the program as admin with that command? (or a different one so will give me my requirements)

EDIT :

I need 2 things

  1. Run as a different user
  2. Run as admin - not just as the admin user but also with full permissions

As this image

enter image description here

Yacov

Posted 2011-12-25T08:49:38.243

Reputation: 182

Do you want it to run as the administrator account, or the account of a different user? If you just want it to run as the administrator, just use the same syntax, but change the username/password – soandos – 2011-12-25T08:58:10.430

@soandos I edited the post – Yacov – 2011-12-25T09:03:26.490

I am assuming that you want a command line way to do this? – soandos – 2011-12-25T09:06:19.793

@soandos Yes - in UI I know how to do it – Yacov – 2011-12-25T09:14:56.613

You should look at my answer. runas is the wrong command to use if you have UAC on, which is what your context menu tells me. – surfasb – 2011-12-25T11:21:05.667

Answers

8

runas does not elevate a program. Starting with Vista, processes are no longer giving admin privileges just because the user has admin credentials. This is because of UAC.

When Vista and Server 2008 came out, this was especially a pain point for system admins because you could not launch programs with admin privileges from a script.

To elevate(the proper term for this process) a program from the commandline, you can do a few ways.

If you just need to elevate one command, you can type it into the start menu and hit CTRL Shift Enter.

If you need to elevate commands from a batchfile, you'll need to covert the script to a VBScript or JScript file. Or just download the excellent Elevate powertoys.

Edit:

For more clarification: http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx

The runas command-line tool, however, still exists in Windows Vista. Unfortunately, it cannot be used for the most common dual account tasks—running Microsoft® Management Console (MMC) snap-ins.
. . .
runas /user:mydomain\admin "mmc.exe %windir%\system32\dsa.msc"

Unfortunately, this does not cause ADU&C to launch. Instead, you receive a runas error that says "The requested operation requires elevation." What is happening in this case is that the MMC executable is marked to run at the highestAvailable privilege level. Since the highestAvailable level for your network administration account is as administrator, launching ADU&C in this manner would require elevation. Since runas does not cause a prompt for elevation, the error occurs.

UAC documentations:

http://technet.microsoft.com/en-US/library/cc753413.aspx

When an administrator logs on to a computer running this version of Windows, the user is assigned two separate access tokens. Windows uses access tokens, which contain a user's group membership, authorization data, and access control data, to control what resources and tasks the user can access. In some previous versions of Windows such as Windows XP, an administrator account received one access token, which included data to grant the user access to all Windows resources.

surfasb

Posted 2011-12-25T08:49:38.243

Reputation: 21 453

This isn't valid if you use the default Administrator account, in this case the program will be launched without any UAC problems – Fez Vrasta – 2017-06-20T15:33:15.473

@FezVrasta That is technically not correct. The Group Policy "Admin Approval Mode for the Built-in Administrator account" needs to be enabled. Note that is is disabled by default on Domain-joined computers. – surfasb – 2017-06-22T16:43:38.937

You just have to enable the admin account, is it what you mean? – Fez Vrasta – 2017-06-22T18:19:55.060

@Fez Vrasta: No. the group policy has to be set correctly, along with the admin approval mode policy. – surfasb – 2017-06-26T17:39:04.663

In my case (Windows 10) it was enough to enable the administrator, the rest worked by itself – Fez Vrasta – 2017-06-26T17:53:34.867

Can you cite a reliable source for your statement that runas doesn't elevate privileges? That would make this answer a better reference. – jstarek – 2011-12-25T14:01:50.193

@jstarek: Besides the UAC documentations, let's do an experiment. If you are an admin account and you have admin approval off, type this into a regular command prompt runas /user:myusername "cmd /k copy c:\windows\write.exe c:\windows\write.bak". Access denied. – surfasb – 2011-12-25T23:18:19.270