0

TLDR version on the bottom. I would like to create a desktop shortcut that would open up command prompt as if I had used the 'Run as Admin' option, but by just double clicking a shortcut and then getting prompted for the password to use with a hardcoded username.

I have done this for 'Active Directory Users and Computers' with the following:

Target: C:\Windows\System32\runas.exe /netonly /user:adminusername@domain "mmc %SystemRoot%\system32\dsa.msc" Start In: %windir%\System32

When I click this shortcut, I get a command prompt just asking for me to type my admin account password and it opens AD Users and Computers with my admin account.

I tried this command with cmd.exe, but it runs it fully as that user instead of what I want which is running it as the logged in non-admin user, but with admin privileges granted by the admin user/password entered in the UAC prompt.

I found a similar question, but the only answer I see that actually answers the question does not do what I want (and I think also does not do what the OP of the other question wanted). https://stackoverflow.com/questions/5944180/how-do-you-run-a-command-as-an-administrator-from-the-windows-command-line#:~:text=84-,All,-you%20have%20to

The answer there suggests:

All you have to do is use the runas command to run your program as Administrator (with a caveat).

runas /user:Administrator "cmdName parameters" In my case, this was: runas /user:Administrator "cmd.exe /C %CD%\installer.cmd %CD%"

My problem with using this is it is different that choosing the run as administrator option from the cmd on the start menu. If you navigate to c:\users%username%\ the command above returns the runas/admin path. If you use the run as administrator option from the start menu, that command would return the user path of the logged in non-admin user. Also, it seems to also not even grant the cmd admin privileges somehow. When I ran net stop spooler from the window that opened, it gave an access denied error.

I know I can just make a shortcut to cmd.exe and in the properties choose run as admin to make it do an UAC prompt. I would like to avoid entering the username each time and want the result to be the same as what I do with my shortcut to Active Directory, where I only need to type the password.

Thanks!

TLDR version: When I click 'Run as administrator' in the command prompt options on the start menu, what command is actually being executed to have it run as the non-admin user, but be able to make administrator level changes?

1
  • 1
    The only way to achieve that, so you don't get UAC is with Task Scheduler.
    – Danijel
    Commented Apr 5 at 17:26

1 Answer 1

0

If you want to create a shortcut to open Command Prompt with administrative privileges without being prompted for a username and password each time, you can follow these steps:

  1. Right-click on your desktop or in the folder where you want to create the shortcut.
  2. Select "New" and then "Shortcut."
  3. In the "Type the location of the item" field, enter the following command:

%windir%\System32\cmd.exe /k %windir%\System32\runas.exe /user:Administrator /savecred "cmd.exe /k"

This command opens Command Prompt (cmd.exe) and uses runas.exe to execute another instance of cmd.exe with administrative privileges (/user:Administrator). The /savecred flag tells runas.exe to save the entered credentials, so you won't be prompted for them again in the future.

  1. Click "Next."

  2. Enter a name for the shortcut, such as "Admin CMD," and click "Finish."

Now, when you double-click the shortcut, it will open Command Prompt with administrative privileges without asking for a username and password. Keep in mind that the first time you run this shortcut, you will still be prompted to enter the administrator password, but after that, it should remember the credentials.

2
  • When I do this using my domain account that is a local administrator on my PC, it runs as that user, but does not actually have admin privileges. 'net stop spooler' results in an access denied error. The command I'm using is: %windir%\System32\cmd.exe /k %windir%\System32\runas.exe /user:adminuser@domain "cmd.exe /k" So how do I force the command to request system admin privileges as if I had chosen 'run as admin' from the start menu option for Command Prompt? When I open it that way, 'net stop spooler' works fine after logging in with the same admin credentials in the UAC prompt .
    – mbelsky
    Commented Apr 9 at 14:53
  • You doesn't need to add username in command. Create the shortcut on your system e.g. on desktop as mentioned steps above without changing in command, just copy and paste. You will prompted to enter admin password once you run that shortcut for one time, then in future, no need. Also when you open the shortcut, both console opens, standard and administrator. Thanks
    – Ajay Kumar
    Commented Apr 10 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .