How to open an elevated cmd using command line for Windows?











up vote
75
down vote

favorite
28












How do I open a elevated command prompt using command lines on a normal cmd?



For example, I use runas /username:admin cmd but the cmd that was opened does not seem to be elevated! Any solutions?










share|improve this question




























    up vote
    75
    down vote

    favorite
    28












    How do I open a elevated command prompt using command lines on a normal cmd?



    For example, I use runas /username:admin cmd but the cmd that was opened does not seem to be elevated! Any solutions?










    share|improve this question


























      up vote
      75
      down vote

      favorite
      28









      up vote
      75
      down vote

      favorite
      28






      28





      How do I open a elevated command prompt using command lines on a normal cmd?



      For example, I use runas /username:admin cmd but the cmd that was opened does not seem to be elevated! Any solutions?










      share|improve this question















      How do I open a elevated command prompt using command lines on a normal cmd?



      For example, I use runas /username:admin cmd but the cmd that was opened does not seem to be elevated! Any solutions?







      windows cmd command






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 5 '16 at 10:38









      vaultah

      27.6k97398




      27.6k97398










      asked Sep 30 '13 at 15:28









      user2633882

      396256




      396256
























          17 Answers
          17






          active

          oldest

          votes

















          up vote
          123
          down vote













          I ran into the same problem and the only way I was able to open the CMD as administrator from CMD was doing the following:




          1. Open CMD

          2. Write powershell -Command "Start-Process cmd -Verb RunAs" and press Enter

          3. A pop-up window will appear asking to open a CMD as administrator






          share|improve this answer



















          • 2




            Good answer. I added and edit I used to make it run in one command line!
            – Preet Sangha
            Oct 20 '15 at 21:28








          • 1




            I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
            – Tony Brix
            Nov 16 '15 at 17:11


















          up vote
          30
          down vote













          According to documentation, the Windows security model...




          does not grant administrative privileges at all
          times. Even administrators run under standard privileges when they
          perform non-administrative tasks that do not require elevated
          privileges.




          You have the Create this task with administrative privileges option in the Create new task dialog (Task Manager > File > Run new task), but there is no built-in way to effectively elevate privileges using the command line.



          However, there are some third party tools (internally relying on Windows APIs) you can use to elevate privileges from the command line:




          NirCmd:




          1. Download it and unzip it.

          2. nircmdc elevate cmd



          windosu:




          1. Install it: npm install -g windosu (requires node.js installed)

          2. sudo cmd






          share|improve this answer



















          • 3




            Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
            – Marcos
            Aug 31 '14 at 12:07










          • Thanks for nircmdc elevate cmd
            – tim
            Jun 1 '16 at 18:32






          • 4




            After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
            – Kip
            Nov 14 '16 at 14:32












          • i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
            – Emmanuel Mahuni
            Dec 5 '17 at 10:55










          • loved windosu :)
            – Finlay Roelofs
            Feb 8 at 16:07


















          up vote
          13
          down vote













          Simple way I did after trying other answers here



          Method 1: WITHOUT a 3rd party program (I used this)




          1. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

            powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"


          2. Move sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

          3. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))


          Method 2: WITH a 3rd party program




          1. Download NirCmd and unzip it.

          2. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

            nircmdc elevate cmd /k "cd /d %cd%"


          3. Move nircmdc.exe and sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

          4. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))






          share|improve this answer























          • While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
            – Ogmios
            Dec 2 '16 at 23:57










          • @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
            – Dheeraj Bhaskar
            Dec 3 '16 at 21:39










          • Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
            – Ogmios
            Dec 7 '16 at 2:42










          • @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
            – Dheeraj Bhaskar
            Dec 7 '16 at 8:38






          • 1




            This should be marked as Answer! Thanks man!
            – Luke
            Sep 7 at 6:28


















          up vote
          9
          down vote













          I use nirsoft programs (eg nircmdc) and sysinternals (eg psexec) all the time. They are very helpful.



          But if you don't want to, or can't, dl a 3rd party program, here's another way, pure Windows.



          Short answer: you can while elevated create a scheduled task with elevated privileges which you can then invoke later while not elevated.



          Middle-length answer: while elevated create task with (but I prefer task scheduler GUI):



          schtasks /create /sc once /tn cmd_elev /tr cmd /rl highest /st 00:00


          Then later, no elevation needed, invoke with



          schtasks /run /tn cmd_elev


          Long answer: There's a lot of fidgety details; see my blog entry "Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"






          share|improve this answer



















          • 1




            This works, verified!!!
            – sactiw
            Apr 15 '16 at 10:50


















          up vote
          3
          down vote













          The following as a batch file will open an elevated command prompt with the path set to the same directory as the one from where the batch file was invoked



          set OLDDIR=%CD%
          powershell -Command "Start-Process cmd -ArgumentList '/K cd %OLDDIR%' -Verb RunAs "





          share|improve this answer




























            up vote
            3
            down vote













            I've been using Elevate for awhile now.



            It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.



            I copy the bin.x86-64elevate.exe from the .zip into C:Program Fileselevate and add that path to my PATH.



            Then GitBash I can run something like elevate sc stop W3SVC to turn off the IIS service.



            Running the command gives me the UAC dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.






            share|improve this answer




























              up vote
              2
              down vote













              My favorite way of doing this is using PsExec.exe from SysInternals, available at http://technet.microsoft.com/en-us/sysinternals/bb897553



              .psexec.exe -accepteula -h -u "$username" -p "$password" cmd.exe


              The "-h" switch is the one doing the magic:



              -h If the target system is Vista or higher, has the process run with the account's elevated token, if available.






              share|improve this answer





















              • To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                – Peter Quiring
                Aug 27 '15 at 19:16










              • Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                – David Rodriguez
                Aug 27 '15 at 19:56










              • I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                – Peter Quiring
                Aug 27 '15 at 20:46


















              up vote
              2
              down vote













              While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)



              The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).




              1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON)

                %SystemRoot%System32cmd.exe /k "cd /d"


              2. su.bat

                @start cmdadm.lnk %cd%



              Run with su.






              share|improve this answer




























                up vote
                2
                down vote













                Similar to some of the other solutions above, I created an elevate batch file which runs an elevated PowerShell window, bypassing the execution policy to enable running everything from simple commands to batch files to complex PowerShell scripts. I recommend sticking it in your C:WindowsSystem32 folder for ease of use.



                The original elevate command executes its task, captures the output, closes the spawned PowerShell window and then returns, writing out the captured output to the original window.



                I created two variants, elevatep and elevatex, which respectively pause and keep the PowerShell window open for more work.



                https://github.com/jt-github/elevate



                And in case my link ever dies, here's the code for the original elevate batch file:



                @Echo Off
                REM Executes a command in an elevated PowerShell window and captures/displays output
                REM Note that any file paths must be fully qualified!

                REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue

                if "%1"=="" (
                REM If no command is passed, simply open an elevated PowerShell window.
                PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
                ) ELSE (
                REM Copy command+arguments (passed as a parameter) into a ps1 file
                REM Start PowerShell with Elevated access (prompting UAC confirmation)
                REM and run the ps1 file
                REM then close elevated window when finished
                REM Output captured results

                IF EXIST %temp%trans.txt del %temp%trans.txt
                Echo %* ^> %temp%trans.txt *^>^&1 > %temp%tmp.ps1
                Echo $error[0] ^| Add-Content %temp%trans.txt -Encoding Default >> %temp%tmp.ps1
                PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%tmp.ps1""' -Verb RunAs}"
                Type %temp%trans.txt
                )





                share|improve this answer




























                  up vote
                  2
                  down vote













                  ..



                  @ECHO OFF
                  SETLOCAL EnableDelayedExpansion EnableExtensions
                  NET SESSION >nul 2>&1
                  IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
                  GOTO :EOF

                  :ELEVATE
                  SET this="%CD%"
                  SET this=!this:=\!

                  MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D "!this!"', '', 'runas', 1);close();"
                  EXIT 1


                  save this script as "god.cmd" in your system32 or whatever your path is directing to....



                  if u open a cmd in e:mypictures and type god
                  it will ask you for credentials and put you back to that same place as the administrator...






                  share|improve this answer























                  • powershell is cool but it needzz modules... im oldscool... just need the system...
                    – jOte-
                    Feb 9 at 1:30










                  • Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                    – script'n'code
                    Oct 1 at 21:56




















                  up vote
                  2
                  down vote













                  Make the batch file save the credentials of the actual administrator account by using the /savecred switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:



                  START c:WindowsSystem32runas.exe /user:Administrator /savecred cmd.exe





                  share|improve this answer






























                    up vote
                    0
                    down vote













                    Can use a temporary environment variable to use with an elevated shortcut (



                    start.cmd



                    setx valueName_betterSpecificForEachCase %~dp0
                    "%~dp0ascladm.lnk"


                    ascladm.lnk (shortcut)



                    _ propertiesadvanced"run as administrator"=yes


                    (to make path changes you'll need to temporarily create the env.Variable)



                    _ propertiestarget="%valueName_betterSpecificForEachCase%ascladm.cmd"

                    _ properties"start in"="%valueName_betterSpecificForEachCase%"


                    ascladm.cmd



                    setx valueName_betterSpecificForEachCase=
                    reg delete HKEY_CURRENT_USEREnvironment /F /V valueName_betterSpecificForEachCase
                    "%~dp0fileName_targetedCmd.cmd"


                    ) (targetedCmd gets executed in elevated cmd window)



                    Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name



                    For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command






                    share|improve this answer























                    • i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                      – Dzmitry Lahoda
                      Oct 14 at 6:43


















                    up vote
                    0
                    down vote













                    I'm not sure the tool ExecElevated.exe (13KB) will do the job....but it might.
                    Or at least be useful for others with similar needs who came to this page as I did (but I didn't find the solution so I ended up creating the tool myself in .Net).



                    It will execute an application with elevated token (in admin mode).
                    But you will get an UAC dialog to confirm! (maybe not if UAC has been disabled, haven't tested it).



                    And the account calling the tool must also have admin. rights of course.



                    Example of use:



                    ExecuteElevated.exe "C:Utilityregjump.exe HKCUSoftwareClasses.pdf"





                    share|improve this answer



















                    • 2




                      I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                      – Giridhar Karnik
                      Apr 12 '15 at 15:51








                    • 1




                      link is broken.
                      – Dzmitry Lahoda
                      Oct 14 at 6:39










                    • Link reestablished, sorry for that
                      – MrCalvin
                      Oct 18 at 22:59


















                    up vote
                    0
                    down vote













                    I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:



                    powershell "start cmd -v runAs"


                    This is just a shorter version of user3018703 excellent
                    solution:



                    powershell -Command "Start-Process cmd -Verb RunAs"





                    share|improve this answer




























                      up vote
                      -1
                      down vote













                      I did it easily by using this following command in cmd



                      runas /netonly /user:AdministratorAdministrator cmd



                      after typing this command, you have to enter your Administrator password(if you don't know your Administrator password leave it blank and press Enter or type something, worked for me)..






                      share|improve this answer





















                      • did not help me
                        – Dzmitry Lahoda
                        Oct 14 at 6:39


















                      up vote
                      -4
                      down vote













                      There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user not username:



                      runas /user:machinenameadminuser cmd


                      See relevant help from Microsoft community.






                      share|improve this answer

















                      • 3




                        This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                        – Constantino Cronemberger
                        Apr 14 '15 at 17:57


















                      up vote
                      -4
                      down vote













                      I used runas /user:domainuser@domain cmd which opened an elevated prompt successfully.






                      share|improve this answer





















                      • It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                        – brokenthorn
                        Nov 20 '14 at 8:28











                      Your Answer






                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "1"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                       

                      draft saved


                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19098101%2fhow-to-open-an-elevated-cmd-using-command-line-for-windows%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest
































                      17 Answers
                      17






                      active

                      oldest

                      votes








                      17 Answers
                      17






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes








                      up vote
                      123
                      down vote













                      I ran into the same problem and the only way I was able to open the CMD as administrator from CMD was doing the following:




                      1. Open CMD

                      2. Write powershell -Command "Start-Process cmd -Verb RunAs" and press Enter

                      3. A pop-up window will appear asking to open a CMD as administrator






                      share|improve this answer



















                      • 2




                        Good answer. I added and edit I used to make it run in one command line!
                        – Preet Sangha
                        Oct 20 '15 at 21:28








                      • 1




                        I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                        – Tony Brix
                        Nov 16 '15 at 17:11















                      up vote
                      123
                      down vote













                      I ran into the same problem and the only way I was able to open the CMD as administrator from CMD was doing the following:




                      1. Open CMD

                      2. Write powershell -Command "Start-Process cmd -Verb RunAs" and press Enter

                      3. A pop-up window will appear asking to open a CMD as administrator






                      share|improve this answer



















                      • 2




                        Good answer. I added and edit I used to make it run in one command line!
                        – Preet Sangha
                        Oct 20 '15 at 21:28








                      • 1




                        I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                        – Tony Brix
                        Nov 16 '15 at 17:11













                      up vote
                      123
                      down vote










                      up vote
                      123
                      down vote









                      I ran into the same problem and the only way I was able to open the CMD as administrator from CMD was doing the following:




                      1. Open CMD

                      2. Write powershell -Command "Start-Process cmd -Verb RunAs" and press Enter

                      3. A pop-up window will appear asking to open a CMD as administrator






                      share|improve this answer














                      I ran into the same problem and the only way I was able to open the CMD as administrator from CMD was doing the following:




                      1. Open CMD

                      2. Write powershell -Command "Start-Process cmd -Verb RunAs" and press Enter

                      3. A pop-up window will appear asking to open a CMD as administrator







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 25 '17 at 19:02









                      Felix Dombek

                      6,210125093




                      6,210125093










                      answered Aug 26 '15 at 1:05









                      user3018703

                      1,231162




                      1,231162








                      • 2




                        Good answer. I added and edit I used to make it run in one command line!
                        – Preet Sangha
                        Oct 20 '15 at 21:28








                      • 1




                        I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                        – Tony Brix
                        Nov 16 '15 at 17:11














                      • 2




                        Good answer. I added and edit I used to make it run in one command line!
                        – Preet Sangha
                        Oct 20 '15 at 21:28








                      • 1




                        I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                        – Tony Brix
                        Nov 16 '15 at 17:11








                      2




                      2




                      Good answer. I added and edit I used to make it run in one command line!
                      – Preet Sangha
                      Oct 20 '15 at 21:28






                      Good answer. I added and edit I used to make it run in one command line!
                      – Preet Sangha
                      Oct 20 '15 at 21:28






                      1




                      1




                      I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                      – Tony Brix
                      Nov 16 '15 at 17:11




                      I created a batch file with this and saved it as admincmd.bat in my windows folder so all I have to do is type "admincmd" hit enter and it opens an admin cmd.(I also added another line to the batch file with "exit" so it closes the non admin cmd window)
                      – Tony Brix
                      Nov 16 '15 at 17:11












                      up vote
                      30
                      down vote













                      According to documentation, the Windows security model...




                      does not grant administrative privileges at all
                      times. Even administrators run under standard privileges when they
                      perform non-administrative tasks that do not require elevated
                      privileges.




                      You have the Create this task with administrative privileges option in the Create new task dialog (Task Manager > File > Run new task), but there is no built-in way to effectively elevate privileges using the command line.



                      However, there are some third party tools (internally relying on Windows APIs) you can use to elevate privileges from the command line:




                      NirCmd:




                      1. Download it and unzip it.

                      2. nircmdc elevate cmd



                      windosu:




                      1. Install it: npm install -g windosu (requires node.js installed)

                      2. sudo cmd






                      share|improve this answer



















                      • 3




                        Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                        – Marcos
                        Aug 31 '14 at 12:07










                      • Thanks for nircmdc elevate cmd
                        – tim
                        Jun 1 '16 at 18:32






                      • 4




                        After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                        – Kip
                        Nov 14 '16 at 14:32












                      • i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                        – Emmanuel Mahuni
                        Dec 5 '17 at 10:55










                      • loved windosu :)
                        – Finlay Roelofs
                        Feb 8 at 16:07















                      up vote
                      30
                      down vote













                      According to documentation, the Windows security model...




                      does not grant administrative privileges at all
                      times. Even administrators run under standard privileges when they
                      perform non-administrative tasks that do not require elevated
                      privileges.




                      You have the Create this task with administrative privileges option in the Create new task dialog (Task Manager > File > Run new task), but there is no built-in way to effectively elevate privileges using the command line.



                      However, there are some third party tools (internally relying on Windows APIs) you can use to elevate privileges from the command line:




                      NirCmd:




                      1. Download it and unzip it.

                      2. nircmdc elevate cmd



                      windosu:




                      1. Install it: npm install -g windosu (requires node.js installed)

                      2. sudo cmd






                      share|improve this answer



















                      • 3




                        Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                        – Marcos
                        Aug 31 '14 at 12:07










                      • Thanks for nircmdc elevate cmd
                        – tim
                        Jun 1 '16 at 18:32






                      • 4




                        After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                        – Kip
                        Nov 14 '16 at 14:32












                      • i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                        – Emmanuel Mahuni
                        Dec 5 '17 at 10:55










                      • loved windosu :)
                        – Finlay Roelofs
                        Feb 8 at 16:07













                      up vote
                      30
                      down vote










                      up vote
                      30
                      down vote









                      According to documentation, the Windows security model...




                      does not grant administrative privileges at all
                      times. Even administrators run under standard privileges when they
                      perform non-administrative tasks that do not require elevated
                      privileges.




                      You have the Create this task with administrative privileges option in the Create new task dialog (Task Manager > File > Run new task), but there is no built-in way to effectively elevate privileges using the command line.



                      However, there are some third party tools (internally relying on Windows APIs) you can use to elevate privileges from the command line:




                      NirCmd:




                      1. Download it and unzip it.

                      2. nircmdc elevate cmd



                      windosu:




                      1. Install it: npm install -g windosu (requires node.js installed)

                      2. sudo cmd






                      share|improve this answer














                      According to documentation, the Windows security model...




                      does not grant administrative privileges at all
                      times. Even administrators run under standard privileges when they
                      perform non-administrative tasks that do not require elevated
                      privileges.




                      You have the Create this task with administrative privileges option in the Create new task dialog (Task Manager > File > Run new task), but there is no built-in way to effectively elevate privileges using the command line.



                      However, there are some third party tools (internally relying on Windows APIs) you can use to elevate privileges from the command line:




                      NirCmd:




                      1. Download it and unzip it.

                      2. nircmdc elevate cmd



                      windosu:




                      1. Install it: npm install -g windosu (requires node.js installed)

                      2. sudo cmd







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 7 '15 at 17:10

























                      answered Mar 21 '14 at 15:28









                      Ricardo Stuven

                      3,24212432




                      3,24212432








                      • 3




                        Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                        – Marcos
                        Aug 31 '14 at 12:07










                      • Thanks for nircmdc elevate cmd
                        – tim
                        Jun 1 '16 at 18:32






                      • 4




                        After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                        – Kip
                        Nov 14 '16 at 14:32












                      • i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                        – Emmanuel Mahuni
                        Dec 5 '17 at 10:55










                      • loved windosu :)
                        – Finlay Roelofs
                        Feb 8 at 16:07














                      • 3




                        Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                        – Marcos
                        Aug 31 '14 at 12:07










                      • Thanks for nircmdc elevate cmd
                        – tim
                        Jun 1 '16 at 18:32






                      • 4




                        After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                        – Kip
                        Nov 14 '16 at 14:32












                      • i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                        – Emmanuel Mahuni
                        Dec 5 '17 at 10:55










                      • loved windosu :)
                        – Finlay Roelofs
                        Feb 8 at 16:07








                      3




                      3




                      Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                      – Marcos
                      Aug 31 '14 at 12:07




                      Thank you, nircmdc elevate route delete 0.0.0.0 mask 0..0.0 192.168.1.1 finally worked. The other runas /user:... ways prompted for a password despite already being an admin (killed batch mode).
                      – Marcos
                      Aug 31 '14 at 12:07












                      Thanks for nircmdc elevate cmd
                      – tim
                      Jun 1 '16 at 18:32




                      Thanks for nircmdc elevate cmd
                      – tim
                      Jun 1 '16 at 18:32




                      4




                      4




                      After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                      – Kip
                      Nov 14 '16 at 14:32






                      After intalling nircmd, to have it work like Linux sudo, create a sudo.bat file in your path with this content: nircmd elevate %*. Then you can do, for example, sudo net stop W3SVC
                      – Kip
                      Nov 14 '16 at 14:32














                      i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                      – Emmanuel Mahuni
                      Dec 5 '17 at 10:55




                      i think windosu is by far the simplest and most elegant way of doing this, especially if you are a dev... thanks man. I feel like I am on nix system :D
                      – Emmanuel Mahuni
                      Dec 5 '17 at 10:55












                      loved windosu :)
                      – Finlay Roelofs
                      Feb 8 at 16:07




                      loved windosu :)
                      – Finlay Roelofs
                      Feb 8 at 16:07










                      up vote
                      13
                      down vote













                      Simple way I did after trying other answers here



                      Method 1: WITHOUT a 3rd party program (I used this)




                      1. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"


                      2. Move sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      3. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))


                      Method 2: WITH a 3rd party program




                      1. Download NirCmd and unzip it.

                      2. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        nircmdc elevate cmd /k "cd /d %cd%"


                      3. Move nircmdc.exe and sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      4. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))






                      share|improve this answer























                      • While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                        – Ogmios
                        Dec 2 '16 at 23:57










                      • @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                        – Dheeraj Bhaskar
                        Dec 3 '16 at 21:39










                      • Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                        – Ogmios
                        Dec 7 '16 at 2:42










                      • @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                        – Dheeraj Bhaskar
                        Dec 7 '16 at 8:38






                      • 1




                        This should be marked as Answer! Thanks man!
                        – Luke
                        Sep 7 at 6:28















                      up vote
                      13
                      down vote













                      Simple way I did after trying other answers here



                      Method 1: WITHOUT a 3rd party program (I used this)




                      1. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"


                      2. Move sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      3. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))


                      Method 2: WITH a 3rd party program




                      1. Download NirCmd and unzip it.

                      2. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        nircmdc elevate cmd /k "cd /d %cd%"


                      3. Move nircmdc.exe and sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      4. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))






                      share|improve this answer























                      • While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                        – Ogmios
                        Dec 2 '16 at 23:57










                      • @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                        – Dheeraj Bhaskar
                        Dec 3 '16 at 21:39










                      • Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                        – Ogmios
                        Dec 7 '16 at 2:42










                      • @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                        – Dheeraj Bhaskar
                        Dec 7 '16 at 8:38






                      • 1




                        This should be marked as Answer! Thanks man!
                        – Luke
                        Sep 7 at 6:28













                      up vote
                      13
                      down vote










                      up vote
                      13
                      down vote









                      Simple way I did after trying other answers here



                      Method 1: WITHOUT a 3rd party program (I used this)




                      1. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"


                      2. Move sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      3. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))


                      Method 2: WITH a 3rd party program




                      1. Download NirCmd and unzip it.

                      2. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        nircmdc elevate cmd /k "cd /d %cd%"


                      3. Move nircmdc.exe and sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      4. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))






                      share|improve this answer














                      Simple way I did after trying other answers here



                      Method 1: WITHOUT a 3rd party program (I used this)




                      1. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        powershell.exe -Command "Start-Process cmd "/k cd /d %cd%" -Verb RunAs"


                      2. Move sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      3. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))


                      Method 2: WITH a 3rd party program




                      1. Download NirCmd and unzip it.

                      2. Create a file called sudo.bat (you can replace sudo with any name you want) with following content

                        nircmdc elevate cmd /k "cd /d %cd%"


                      3. Move nircmdc.exe and sudo.bat to a folder in your PATH; if you don't know what that means, just move these files to c:windows

                      4. Now sudo will work in Run dialog (win+r) or in explorer address bar (this is the best part :))







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 3 '16 at 21:40

























                      answered Oct 29 '16 at 16:40









                      Dheeraj Bhaskar

                      14k74252




                      14k74252












                      • While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                        – Ogmios
                        Dec 2 '16 at 23:57










                      • @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                        – Dheeraj Bhaskar
                        Dec 3 '16 at 21:39










                      • Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                        – Ogmios
                        Dec 7 '16 at 2:42










                      • @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                        – Dheeraj Bhaskar
                        Dec 7 '16 at 8:38






                      • 1




                        This should be marked as Answer! Thanks man!
                        – Luke
                        Sep 7 at 6:28


















                      • While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                        – Ogmios
                        Dec 2 '16 at 23:57










                      • @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                        – Dheeraj Bhaskar
                        Dec 3 '16 at 21:39










                      • Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                        – Ogmios
                        Dec 7 '16 at 2:42










                      • @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                        – Dheeraj Bhaskar
                        Dec 7 '16 at 8:38






                      • 1




                        This should be marked as Answer! Thanks man!
                        – Luke
                        Sep 7 at 6:28
















                      While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                      – Ogmios
                      Dec 2 '16 at 23:57




                      While both solutions work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused. (Tested on Win10x64 v1607 build14393.447.)
                      – Ogmios
                      Dec 2 '16 at 23:57












                      @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                      – Dheeraj Bhaskar
                      Dec 3 '16 at 21:39




                      @Ogmios that's rather odd. does the dialog work properly when not initiated like this? I've been very happily using this without such issues. Maybe it's because of some other configuration that you've changed?
                      – Dheeraj Bhaskar
                      Dec 3 '16 at 21:39












                      Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                      – Ogmios
                      Dec 7 '16 at 2:42




                      Yes, the UAC dialog works as expected in all other situations (I've encountered). This is the only exception. And of course I have changed my system in other ways, but I haven't found anything that might have a hidden effect on this dialog.
                      – Ogmios
                      Dec 7 '16 at 2:42












                      @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                      – Dheeraj Bhaskar
                      Dec 7 '16 at 8:38




                      @Ogmios sorry then mate, I can't think of anything else you can do to fix this. You should probably try the other solutions to see if they are better for you. Cheers
                      – Dheeraj Bhaskar
                      Dec 7 '16 at 8:38




                      1




                      1




                      This should be marked as Answer! Thanks man!
                      – Luke
                      Sep 7 at 6:28




                      This should be marked as Answer! Thanks man!
                      – Luke
                      Sep 7 at 6:28










                      up vote
                      9
                      down vote













                      I use nirsoft programs (eg nircmdc) and sysinternals (eg psexec) all the time. They are very helpful.



                      But if you don't want to, or can't, dl a 3rd party program, here's another way, pure Windows.



                      Short answer: you can while elevated create a scheduled task with elevated privileges which you can then invoke later while not elevated.



                      Middle-length answer: while elevated create task with (but I prefer task scheduler GUI):



                      schtasks /create /sc once /tn cmd_elev /tr cmd /rl highest /st 00:00


                      Then later, no elevation needed, invoke with



                      schtasks /run /tn cmd_elev


                      Long answer: There's a lot of fidgety details; see my blog entry "Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"






                      share|improve this answer



















                      • 1




                        This works, verified!!!
                        – sactiw
                        Apr 15 '16 at 10:50















                      up vote
                      9
                      down vote













                      I use nirsoft programs (eg nircmdc) and sysinternals (eg psexec) all the time. They are very helpful.



                      But if you don't want to, or can't, dl a 3rd party program, here's another way, pure Windows.



                      Short answer: you can while elevated create a scheduled task with elevated privileges which you can then invoke later while not elevated.



                      Middle-length answer: while elevated create task with (but I prefer task scheduler GUI):



                      schtasks /create /sc once /tn cmd_elev /tr cmd /rl highest /st 00:00


                      Then later, no elevation needed, invoke with



                      schtasks /run /tn cmd_elev


                      Long answer: There's a lot of fidgety details; see my blog entry "Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"






                      share|improve this answer



















                      • 1




                        This works, verified!!!
                        – sactiw
                        Apr 15 '16 at 10:50













                      up vote
                      9
                      down vote










                      up vote
                      9
                      down vote









                      I use nirsoft programs (eg nircmdc) and sysinternals (eg psexec) all the time. They are very helpful.



                      But if you don't want to, or can't, dl a 3rd party program, here's another way, pure Windows.



                      Short answer: you can while elevated create a scheduled task with elevated privileges which you can then invoke later while not elevated.



                      Middle-length answer: while elevated create task with (but I prefer task scheduler GUI):



                      schtasks /create /sc once /tn cmd_elev /tr cmd /rl highest /st 00:00


                      Then later, no elevation needed, invoke with



                      schtasks /run /tn cmd_elev


                      Long answer: There's a lot of fidgety details; see my blog entry "Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"






                      share|improve this answer














                      I use nirsoft programs (eg nircmdc) and sysinternals (eg psexec) all the time. They are very helpful.



                      But if you don't want to, or can't, dl a 3rd party program, here's another way, pure Windows.



                      Short answer: you can while elevated create a scheduled task with elevated privileges which you can then invoke later while not elevated.



                      Middle-length answer: while elevated create task with (but I prefer task scheduler GUI):



                      schtasks /create /sc once /tn cmd_elev /tr cmd /rl highest /st 00:00


                      Then later, no elevation needed, invoke with



                      schtasks /run /tn cmd_elev


                      Long answer: There's a lot of fidgety details; see my blog entry "Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 23 '15 at 7:55









                      bluish

                      13.6k1692146




                      13.6k1692146










                      answered Feb 19 '15 at 7:59









                      john v kumpf

                      19112




                      19112








                      • 1




                        This works, verified!!!
                        – sactiw
                        Apr 15 '16 at 10:50














                      • 1




                        This works, verified!!!
                        – sactiw
                        Apr 15 '16 at 10:50








                      1




                      1




                      This works, verified!!!
                      – sactiw
                      Apr 15 '16 at 10:50




                      This works, verified!!!
                      – sactiw
                      Apr 15 '16 at 10:50










                      up vote
                      3
                      down vote













                      The following as a batch file will open an elevated command prompt with the path set to the same directory as the one from where the batch file was invoked



                      set OLDDIR=%CD%
                      powershell -Command "Start-Process cmd -ArgumentList '/K cd %OLDDIR%' -Verb RunAs "





                      share|improve this answer

























                        up vote
                        3
                        down vote













                        The following as a batch file will open an elevated command prompt with the path set to the same directory as the one from where the batch file was invoked



                        set OLDDIR=%CD%
                        powershell -Command "Start-Process cmd -ArgumentList '/K cd %OLDDIR%' -Verb RunAs "





                        share|improve this answer























                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          The following as a batch file will open an elevated command prompt with the path set to the same directory as the one from where the batch file was invoked



                          set OLDDIR=%CD%
                          powershell -Command "Start-Process cmd -ArgumentList '/K cd %OLDDIR%' -Verb RunAs "





                          share|improve this answer












                          The following as a batch file will open an elevated command prompt with the path set to the same directory as the one from where the batch file was invoked



                          set OLDDIR=%CD%
                          powershell -Command "Start-Process cmd -ArgumentList '/K cd %OLDDIR%' -Verb RunAs "






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 14 '17 at 0:25









                          statler

                          447512




                          447512






















                              up vote
                              3
                              down vote













                              I've been using Elevate for awhile now.



                              It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.



                              I copy the bin.x86-64elevate.exe from the .zip into C:Program Fileselevate and add that path to my PATH.



                              Then GitBash I can run something like elevate sc stop W3SVC to turn off the IIS service.



                              Running the command gives me the UAC dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.






                              share|improve this answer

























                                up vote
                                3
                                down vote













                                I've been using Elevate for awhile now.



                                It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.



                                I copy the bin.x86-64elevate.exe from the .zip into C:Program Fileselevate and add that path to my PATH.



                                Then GitBash I can run something like elevate sc stop W3SVC to turn off the IIS service.



                                Running the command gives me the UAC dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.






                                share|improve this answer























                                  up vote
                                  3
                                  down vote










                                  up vote
                                  3
                                  down vote









                                  I've been using Elevate for awhile now.



                                  It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.



                                  I copy the bin.x86-64elevate.exe from the .zip into C:Program Fileselevate and add that path to my PATH.



                                  Then GitBash I can run something like elevate sc stop W3SVC to turn off the IIS service.



                                  Running the command gives me the UAC dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.






                                  share|improve this answer












                                  I've been using Elevate for awhile now.



                                  It's description - This utility executes a command with UAC privilege elevation. This is useful for working inside command prompts or with batch files.



                                  I copy the bin.x86-64elevate.exe from the .zip into C:Program Fileselevate and add that path to my PATH.



                                  Then GitBash I can run something like elevate sc stop W3SVC to turn off the IIS service.



                                  Running the command gives me the UAC dialog, properly focused with keyboard control and upon accepting the dialog I return to my shell.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jun 11 '17 at 16:33









                                  seangwright

                                  9,23432434




                                  9,23432434






















                                      up vote
                                      2
                                      down vote













                                      My favorite way of doing this is using PsExec.exe from SysInternals, available at http://technet.microsoft.com/en-us/sysinternals/bb897553



                                      .psexec.exe -accepteula -h -u "$username" -p "$password" cmd.exe


                                      The "-h" switch is the one doing the magic:



                                      -h If the target system is Vista or higher, has the process run with the account's elevated token, if available.






                                      share|improve this answer





















                                      • To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                        – Peter Quiring
                                        Aug 27 '15 at 19:16










                                      • Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                        – David Rodriguez
                                        Aug 27 '15 at 19:56










                                      • I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                        – Peter Quiring
                                        Aug 27 '15 at 20:46















                                      up vote
                                      2
                                      down vote













                                      My favorite way of doing this is using PsExec.exe from SysInternals, available at http://technet.microsoft.com/en-us/sysinternals/bb897553



                                      .psexec.exe -accepteula -h -u "$username" -p "$password" cmd.exe


                                      The "-h" switch is the one doing the magic:



                                      -h If the target system is Vista or higher, has the process run with the account's elevated token, if available.






                                      share|improve this answer





















                                      • To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                        – Peter Quiring
                                        Aug 27 '15 at 19:16










                                      • Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                        – David Rodriguez
                                        Aug 27 '15 at 19:56










                                      • I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                        – Peter Quiring
                                        Aug 27 '15 at 20:46













                                      up vote
                                      2
                                      down vote










                                      up vote
                                      2
                                      down vote









                                      My favorite way of doing this is using PsExec.exe from SysInternals, available at http://technet.microsoft.com/en-us/sysinternals/bb897553



                                      .psexec.exe -accepteula -h -u "$username" -p "$password" cmd.exe


                                      The "-h" switch is the one doing the magic:



                                      -h If the target system is Vista or higher, has the process run with the account's elevated token, if available.






                                      share|improve this answer












                                      My favorite way of doing this is using PsExec.exe from SysInternals, available at http://technet.microsoft.com/en-us/sysinternals/bb897553



                                      .psexec.exe -accepteula -h -u "$username" -p "$password" cmd.exe


                                      The "-h" switch is the one doing the magic:



                                      -h If the target system is Vista or higher, has the process run with the account's elevated token, if available.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Sep 7 '14 at 14:11









                                      David Rodriguez

                                      1,73511011




                                      1,73511011












                                      • To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                        – Peter Quiring
                                        Aug 27 '15 at 19:16










                                      • Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                        – David Rodriguez
                                        Aug 27 '15 at 19:56










                                      • I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                        – Peter Quiring
                                        Aug 27 '15 at 20:46


















                                      • To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                        – Peter Quiring
                                        Aug 27 '15 at 19:16










                                      • Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                        – David Rodriguez
                                        Aug 27 '15 at 19:56










                                      • I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                        – Peter Quiring
                                        Aug 27 '15 at 20:46
















                                      To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                      – Peter Quiring
                                      Aug 27 '15 at 19:16




                                      To get this to work you must edit the properties of psexec.exe and on the compatibility tab check "Run as Administrator". Otherwise you will get error : PSEXESVC not installed. But psexec causes issues with the tab key in the cmd.exe. Can't use tab to complete folder names.
                                      – Peter Quiring
                                      Aug 27 '15 at 19:16












                                      Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                      – David Rodriguez
                                      Aug 27 '15 at 19:56




                                      Not sure on which environment you tried but I didn't need to change the "Run as Administrator" setting (are you trying to run the cmd.exe on a remote machine from yours?). Also no issues with tab key, I can successfully complete files and folders names (at least tested on Win8.1 and Win10, running from both cmd and PowerShell command lines)
                                      – David Rodriguez
                                      Aug 27 '15 at 19:56












                                      I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                      – Peter Quiring
                                      Aug 27 '15 at 20:46




                                      I'm using Win10 and running it locally. Not sure why it happens to me and not you. I did get nircmd to work and it doesn't cause tab issue.
                                      – Peter Quiring
                                      Aug 27 '15 at 20:46










                                      up vote
                                      2
                                      down vote













                                      While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)



                                      The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).




                                      1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON)

                                        %SystemRoot%System32cmd.exe /k "cd /d"


                                      2. su.bat

                                        @start cmdadm.lnk %cd%



                                      Run with su.






                                      share|improve this answer

























                                        up vote
                                        2
                                        down vote













                                        While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)



                                        The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).




                                        1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON)

                                          %SystemRoot%System32cmd.exe /k "cd /d"


                                        2. su.bat

                                          @start cmdadm.lnk %cd%



                                        Run with su.






                                        share|improve this answer























                                          up vote
                                          2
                                          down vote










                                          up vote
                                          2
                                          down vote









                                          While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)



                                          The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).




                                          1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON)

                                            %SystemRoot%System32cmd.exe /k "cd /d"


                                          2. su.bat

                                            @start cmdadm.lnk %cd%



                                          Run with su.






                                          share|improve this answer












                                          While both solutions provided by Dheeraj Bhaskar work, unfortunately they will result in the UAC dialog showing up on top (z-order-wise) but not getting focused (the focused window is the caller cmd/powershell window), thus I either need to grab the mouse and click "yes", or to select the UAC window using Alt+Shift+Tab. (Tested on Win10x64 v1607 build14393.447; UAC = "[...] do not dim [...]".)



                                          The following solution is a bit awkward as it uses two files, but it preserves the correct focus order, so no extra mouse / keyboard actions are required (besides confirming the UAC dialog: Alt+Y).




                                          1. cmdadm.lnk (shortcut properties / Advanced... / Run as administrator = ON)

                                            %SystemRoot%System32cmd.exe /k "cd /d"


                                          2. su.bat

                                            @start cmdadm.lnk %cd%



                                          Run with su.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Dec 3 '16 at 0:18









                                          Ogmios

                                          479310




                                          479310






















                                              up vote
                                              2
                                              down vote













                                              Similar to some of the other solutions above, I created an elevate batch file which runs an elevated PowerShell window, bypassing the execution policy to enable running everything from simple commands to batch files to complex PowerShell scripts. I recommend sticking it in your C:WindowsSystem32 folder for ease of use.



                                              The original elevate command executes its task, captures the output, closes the spawned PowerShell window and then returns, writing out the captured output to the original window.



                                              I created two variants, elevatep and elevatex, which respectively pause and keep the PowerShell window open for more work.



                                              https://github.com/jt-github/elevate



                                              And in case my link ever dies, here's the code for the original elevate batch file:



                                              @Echo Off
                                              REM Executes a command in an elevated PowerShell window and captures/displays output
                                              REM Note that any file paths must be fully qualified!

                                              REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue

                                              if "%1"=="" (
                                              REM If no command is passed, simply open an elevated PowerShell window.
                                              PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
                                              ) ELSE (
                                              REM Copy command+arguments (passed as a parameter) into a ps1 file
                                              REM Start PowerShell with Elevated access (prompting UAC confirmation)
                                              REM and run the ps1 file
                                              REM then close elevated window when finished
                                              REM Output captured results

                                              IF EXIST %temp%trans.txt del %temp%trans.txt
                                              Echo %* ^> %temp%trans.txt *^>^&1 > %temp%tmp.ps1
                                              Echo $error[0] ^| Add-Content %temp%trans.txt -Encoding Default >> %temp%tmp.ps1
                                              PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%tmp.ps1""' -Verb RunAs}"
                                              Type %temp%trans.txt
                                              )





                                              share|improve this answer

























                                                up vote
                                                2
                                                down vote













                                                Similar to some of the other solutions above, I created an elevate batch file which runs an elevated PowerShell window, bypassing the execution policy to enable running everything from simple commands to batch files to complex PowerShell scripts. I recommend sticking it in your C:WindowsSystem32 folder for ease of use.



                                                The original elevate command executes its task, captures the output, closes the spawned PowerShell window and then returns, writing out the captured output to the original window.



                                                I created two variants, elevatep and elevatex, which respectively pause and keep the PowerShell window open for more work.



                                                https://github.com/jt-github/elevate



                                                And in case my link ever dies, here's the code for the original elevate batch file:



                                                @Echo Off
                                                REM Executes a command in an elevated PowerShell window and captures/displays output
                                                REM Note that any file paths must be fully qualified!

                                                REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue

                                                if "%1"=="" (
                                                REM If no command is passed, simply open an elevated PowerShell window.
                                                PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
                                                ) ELSE (
                                                REM Copy command+arguments (passed as a parameter) into a ps1 file
                                                REM Start PowerShell with Elevated access (prompting UAC confirmation)
                                                REM and run the ps1 file
                                                REM then close elevated window when finished
                                                REM Output captured results

                                                IF EXIST %temp%trans.txt del %temp%trans.txt
                                                Echo %* ^> %temp%trans.txt *^>^&1 > %temp%tmp.ps1
                                                Echo $error[0] ^| Add-Content %temp%trans.txt -Encoding Default >> %temp%tmp.ps1
                                                PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%tmp.ps1""' -Verb RunAs}"
                                                Type %temp%trans.txt
                                                )





                                                share|improve this answer























                                                  up vote
                                                  2
                                                  down vote










                                                  up vote
                                                  2
                                                  down vote









                                                  Similar to some of the other solutions above, I created an elevate batch file which runs an elevated PowerShell window, bypassing the execution policy to enable running everything from simple commands to batch files to complex PowerShell scripts. I recommend sticking it in your C:WindowsSystem32 folder for ease of use.



                                                  The original elevate command executes its task, captures the output, closes the spawned PowerShell window and then returns, writing out the captured output to the original window.



                                                  I created two variants, elevatep and elevatex, which respectively pause and keep the PowerShell window open for more work.



                                                  https://github.com/jt-github/elevate



                                                  And in case my link ever dies, here's the code for the original elevate batch file:



                                                  @Echo Off
                                                  REM Executes a command in an elevated PowerShell window and captures/displays output
                                                  REM Note that any file paths must be fully qualified!

                                                  REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue

                                                  if "%1"=="" (
                                                  REM If no command is passed, simply open an elevated PowerShell window.
                                                  PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
                                                  ) ELSE (
                                                  REM Copy command+arguments (passed as a parameter) into a ps1 file
                                                  REM Start PowerShell with Elevated access (prompting UAC confirmation)
                                                  REM and run the ps1 file
                                                  REM then close elevated window when finished
                                                  REM Output captured results

                                                  IF EXIST %temp%trans.txt del %temp%trans.txt
                                                  Echo %* ^> %temp%trans.txt *^>^&1 > %temp%tmp.ps1
                                                  Echo $error[0] ^| Add-Content %temp%trans.txt -Encoding Default >> %temp%tmp.ps1
                                                  PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%tmp.ps1""' -Verb RunAs}"
                                                  Type %temp%trans.txt
                                                  )





                                                  share|improve this answer












                                                  Similar to some of the other solutions above, I created an elevate batch file which runs an elevated PowerShell window, bypassing the execution policy to enable running everything from simple commands to batch files to complex PowerShell scripts. I recommend sticking it in your C:WindowsSystem32 folder for ease of use.



                                                  The original elevate command executes its task, captures the output, closes the spawned PowerShell window and then returns, writing out the captured output to the original window.



                                                  I created two variants, elevatep and elevatex, which respectively pause and keep the PowerShell window open for more work.



                                                  https://github.com/jt-github/elevate



                                                  And in case my link ever dies, here's the code for the original elevate batch file:



                                                  @Echo Off
                                                  REM Executes a command in an elevated PowerShell window and captures/displays output
                                                  REM Note that any file paths must be fully qualified!

                                                  REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue

                                                  if "%1"=="" (
                                                  REM If no command is passed, simply open an elevated PowerShell window.
                                                  PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
                                                  ) ELSE (
                                                  REM Copy command+arguments (passed as a parameter) into a ps1 file
                                                  REM Start PowerShell with Elevated access (prompting UAC confirmation)
                                                  REM and run the ps1 file
                                                  REM then close elevated window when finished
                                                  REM Output captured results

                                                  IF EXIST %temp%trans.txt del %temp%trans.txt
                                                  Echo %* ^> %temp%trans.txt *^>^&1 > %temp%tmp.ps1
                                                  Echo $error[0] ^| Add-Content %temp%trans.txt -Encoding Default >> %temp%tmp.ps1
                                                  PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%tmp.ps1""' -Verb RunAs}"
                                                  Type %temp%trans.txt
                                                  )






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Mar 7 '17 at 14:38









                                                  Shadow Lynx

                                                  211




                                                  211






















                                                      up vote
                                                      2
                                                      down vote













                                                      ..



                                                      @ECHO OFF
                                                      SETLOCAL EnableDelayedExpansion EnableExtensions
                                                      NET SESSION >nul 2>&1
                                                      IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
                                                      GOTO :EOF

                                                      :ELEVATE
                                                      SET this="%CD%"
                                                      SET this=!this:=\!

                                                      MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D "!this!"', '', 'runas', 1);close();"
                                                      EXIT 1


                                                      save this script as "god.cmd" in your system32 or whatever your path is directing to....



                                                      if u open a cmd in e:mypictures and type god
                                                      it will ask you for credentials and put you back to that same place as the administrator...






                                                      share|improve this answer























                                                      • powershell is cool but it needzz modules... im oldscool... just need the system...
                                                        – jOte-
                                                        Feb 9 at 1:30










                                                      • Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                        – script'n'code
                                                        Oct 1 at 21:56

















                                                      up vote
                                                      2
                                                      down vote













                                                      ..



                                                      @ECHO OFF
                                                      SETLOCAL EnableDelayedExpansion EnableExtensions
                                                      NET SESSION >nul 2>&1
                                                      IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
                                                      GOTO :EOF

                                                      :ELEVATE
                                                      SET this="%CD%"
                                                      SET this=!this:=\!

                                                      MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D "!this!"', '', 'runas', 1);close();"
                                                      EXIT 1


                                                      save this script as "god.cmd" in your system32 or whatever your path is directing to....



                                                      if u open a cmd in e:mypictures and type god
                                                      it will ask you for credentials and put you back to that same place as the administrator...






                                                      share|improve this answer























                                                      • powershell is cool but it needzz modules... im oldscool... just need the system...
                                                        – jOte-
                                                        Feb 9 at 1:30










                                                      • Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                        – script'n'code
                                                        Oct 1 at 21:56















                                                      up vote
                                                      2
                                                      down vote










                                                      up vote
                                                      2
                                                      down vote









                                                      ..



                                                      @ECHO OFF
                                                      SETLOCAL EnableDelayedExpansion EnableExtensions
                                                      NET SESSION >nul 2>&1
                                                      IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
                                                      GOTO :EOF

                                                      :ELEVATE
                                                      SET this="%CD%"
                                                      SET this=!this:=\!

                                                      MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D "!this!"', '', 'runas', 1);close();"
                                                      EXIT 1


                                                      save this script as "god.cmd" in your system32 or whatever your path is directing to....



                                                      if u open a cmd in e:mypictures and type god
                                                      it will ask you for credentials and put you back to that same place as the administrator...






                                                      share|improve this answer














                                                      ..



                                                      @ECHO OFF
                                                      SETLOCAL EnableDelayedExpansion EnableExtensions
                                                      NET SESSION >nul 2>&1
                                                      IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
                                                      GOTO :EOF

                                                      :ELEVATE
                                                      SET this="%CD%"
                                                      SET this=!this:=\!

                                                      MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D "!this!"', '', 'runas', 1);close();"
                                                      EXIT 1


                                                      save this script as "god.cmd" in your system32 or whatever your path is directing to....



                                                      if u open a cmd in e:mypictures and type god
                                                      it will ask you for credentials and put you back to that same place as the administrator...







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Feb 9 at 7:10

























                                                      answered Feb 9 at 0:40









                                                      jOte-

                                                      313




                                                      313












                                                      • powershell is cool but it needzz modules... im oldscool... just need the system...
                                                        – jOte-
                                                        Feb 9 at 1:30










                                                      • Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                        – script'n'code
                                                        Oct 1 at 21:56




















                                                      • powershell is cool but it needzz modules... im oldscool... just need the system...
                                                        – jOte-
                                                        Feb 9 at 1:30










                                                      • Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                        – script'n'code
                                                        Oct 1 at 21:56


















                                                      powershell is cool but it needzz modules... im oldscool... just need the system...
                                                      – jOte-
                                                      Feb 9 at 1:30




                                                      powershell is cool but it needzz modules... im oldscool... just need the system...
                                                      – jOte-
                                                      Feb 9 at 1:30












                                                      Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                      – script'n'code
                                                      Oct 1 at 21:56






                                                      Does this elevation method/trick also work for long paths/filenames? Or am i supposed to use "%~snx0" or "%~dpsnx0" instead?
                                                      – script'n'code
                                                      Oct 1 at 21:56












                                                      up vote
                                                      2
                                                      down vote













                                                      Make the batch file save the credentials of the actual administrator account by using the /savecred switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:



                                                      START c:WindowsSystem32runas.exe /user:Administrator /savecred cmd.exe





                                                      share|improve this answer



























                                                        up vote
                                                        2
                                                        down vote













                                                        Make the batch file save the credentials of the actual administrator account by using the /savecred switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:



                                                        START c:WindowsSystem32runas.exe /user:Administrator /savecred cmd.exe





                                                        share|improve this answer

























                                                          up vote
                                                          2
                                                          down vote










                                                          up vote
                                                          2
                                                          down vote









                                                          Make the batch file save the credentials of the actual administrator account by using the /savecred switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:



                                                          START c:WindowsSystem32runas.exe /user:Administrator /savecred cmd.exe





                                                          share|improve this answer














                                                          Make the batch file save the credentials of the actual administrator account by using the /savecred switch. This will prompt for credentials the first time and then store the encrypted password in credential manager. Then for all subsequent times the batch runs it will run as the full admin but not prompt for credentials because they are stored encrypted in credential manager and the end user is unable to get the password. The following should open an elevated CMD with full administrator privileges and will only prompt for password the first time:



                                                          START c:WindowsSystem32runas.exe /user:Administrator /savecred cmd.exe






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Jun 6 at 8:39









                                                          bluish

                                                          13.6k1692146




                                                          13.6k1692146










                                                          answered May 17 at 18:32









                                                          Stefan Gadecki

                                                          211




                                                          211






















                                                              up vote
                                                              0
                                                              down vote













                                                              Can use a temporary environment variable to use with an elevated shortcut (



                                                              start.cmd



                                                              setx valueName_betterSpecificForEachCase %~dp0
                                                              "%~dp0ascladm.lnk"


                                                              ascladm.lnk (shortcut)



                                                              _ propertiesadvanced"run as administrator"=yes


                                                              (to make path changes you'll need to temporarily create the env.Variable)



                                                              _ propertiestarget="%valueName_betterSpecificForEachCase%ascladm.cmd"

                                                              _ properties"start in"="%valueName_betterSpecificForEachCase%"


                                                              ascladm.cmd



                                                              setx valueName_betterSpecificForEachCase=
                                                              reg delete HKEY_CURRENT_USEREnvironment /F /V valueName_betterSpecificForEachCase
                                                              "%~dp0fileName_targetedCmd.cmd"


                                                              ) (targetedCmd gets executed in elevated cmd window)



                                                              Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name



                                                              For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command






                                                              share|improve this answer























                                                              • i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:43















                                                              up vote
                                                              0
                                                              down vote













                                                              Can use a temporary environment variable to use with an elevated shortcut (



                                                              start.cmd



                                                              setx valueName_betterSpecificForEachCase %~dp0
                                                              "%~dp0ascladm.lnk"


                                                              ascladm.lnk (shortcut)



                                                              _ propertiesadvanced"run as administrator"=yes


                                                              (to make path changes you'll need to temporarily create the env.Variable)



                                                              _ propertiestarget="%valueName_betterSpecificForEachCase%ascladm.cmd"

                                                              _ properties"start in"="%valueName_betterSpecificForEachCase%"


                                                              ascladm.cmd



                                                              setx valueName_betterSpecificForEachCase=
                                                              reg delete HKEY_CURRENT_USEREnvironment /F /V valueName_betterSpecificForEachCase
                                                              "%~dp0fileName_targetedCmd.cmd"


                                                              ) (targetedCmd gets executed in elevated cmd window)



                                                              Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name



                                                              For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command






                                                              share|improve this answer























                                                              • i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:43













                                                              up vote
                                                              0
                                                              down vote










                                                              up vote
                                                              0
                                                              down vote









                                                              Can use a temporary environment variable to use with an elevated shortcut (



                                                              start.cmd



                                                              setx valueName_betterSpecificForEachCase %~dp0
                                                              "%~dp0ascladm.lnk"


                                                              ascladm.lnk (shortcut)



                                                              _ propertiesadvanced"run as administrator"=yes


                                                              (to make path changes you'll need to temporarily create the env.Variable)



                                                              _ propertiestarget="%valueName_betterSpecificForEachCase%ascladm.cmd"

                                                              _ properties"start in"="%valueName_betterSpecificForEachCase%"


                                                              ascladm.cmd



                                                              setx valueName_betterSpecificForEachCase=
                                                              reg delete HKEY_CURRENT_USEREnvironment /F /V valueName_betterSpecificForEachCase
                                                              "%~dp0fileName_targetedCmd.cmd"


                                                              ) (targetedCmd gets executed in elevated cmd window)



                                                              Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name



                                                              For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command






                                                              share|improve this answer














                                                              Can use a temporary environment variable to use with an elevated shortcut (



                                                              start.cmd



                                                              setx valueName_betterSpecificForEachCase %~dp0
                                                              "%~dp0ascladm.lnk"


                                                              ascladm.lnk (shortcut)



                                                              _ propertiesadvanced"run as administrator"=yes


                                                              (to make path changes you'll need to temporarily create the env.Variable)



                                                              _ propertiestarget="%valueName_betterSpecificForEachCase%ascladm.cmd"

                                                              _ properties"start in"="%valueName_betterSpecificForEachCase%"


                                                              ascladm.cmd



                                                              setx valueName_betterSpecificForEachCase=
                                                              reg delete HKEY_CURRENT_USEREnvironment /F /V valueName_betterSpecificForEachCase
                                                              "%~dp0fileName_targetedCmd.cmd"


                                                              ) (targetedCmd gets executed in elevated cmd window)



                                                              Although it is 3 files ,you can place everything (including targetedCmd) in some subfolder (do not forget to add the folderName to the patches) and rename "start.cmd" to targeted's one name



                                                              For me it looks like most native way of doing this ,whilst cmd doesn't have the needed command







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Jul 26 at 6:28









                                                              Jee Mok

                                                              1,0252925




                                                              1,0252925










                                                              answered Jul 25 at 23:28









                                                              ilia

                                                              14




                                                              14












                                                              • i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:43


















                                                              • i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:43
















                                                              i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                              – Dzmitry Lahoda
                                                              Oct 14 at 6:43




                                                              i have read all of above solutions and understood them. i do not understand steps of yours. i am choosing solution with best pros and cons.
                                                              – Dzmitry Lahoda
                                                              Oct 14 at 6:43










                                                              up vote
                                                              0
                                                              down vote













                                                              I'm not sure the tool ExecElevated.exe (13KB) will do the job....but it might.
                                                              Or at least be useful for others with similar needs who came to this page as I did (but I didn't find the solution so I ended up creating the tool myself in .Net).



                                                              It will execute an application with elevated token (in admin mode).
                                                              But you will get an UAC dialog to confirm! (maybe not if UAC has been disabled, haven't tested it).



                                                              And the account calling the tool must also have admin. rights of course.



                                                              Example of use:



                                                              ExecuteElevated.exe "C:Utilityregjump.exe HKCUSoftwareClasses.pdf"





                                                              share|improve this answer



















                                                              • 2




                                                                I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                                – Giridhar Karnik
                                                                Apr 12 '15 at 15:51








                                                              • 1




                                                                link is broken.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:39










                                                              • Link reestablished, sorry for that
                                                                – MrCalvin
                                                                Oct 18 at 22:59















                                                              up vote
                                                              0
                                                              down vote













                                                              I'm not sure the tool ExecElevated.exe (13KB) will do the job....but it might.
                                                              Or at least be useful for others with similar needs who came to this page as I did (but I didn't find the solution so I ended up creating the tool myself in .Net).



                                                              It will execute an application with elevated token (in admin mode).
                                                              But you will get an UAC dialog to confirm! (maybe not if UAC has been disabled, haven't tested it).



                                                              And the account calling the tool must also have admin. rights of course.



                                                              Example of use:



                                                              ExecuteElevated.exe "C:Utilityregjump.exe HKCUSoftwareClasses.pdf"





                                                              share|improve this answer



















                                                              • 2




                                                                I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                                – Giridhar Karnik
                                                                Apr 12 '15 at 15:51








                                                              • 1




                                                                link is broken.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:39










                                                              • Link reestablished, sorry for that
                                                                – MrCalvin
                                                                Oct 18 at 22:59













                                                              up vote
                                                              0
                                                              down vote










                                                              up vote
                                                              0
                                                              down vote









                                                              I'm not sure the tool ExecElevated.exe (13KB) will do the job....but it might.
                                                              Or at least be useful for others with similar needs who came to this page as I did (but I didn't find the solution so I ended up creating the tool myself in .Net).



                                                              It will execute an application with elevated token (in admin mode).
                                                              But you will get an UAC dialog to confirm! (maybe not if UAC has been disabled, haven't tested it).



                                                              And the account calling the tool must also have admin. rights of course.



                                                              Example of use:



                                                              ExecuteElevated.exe "C:Utilityregjump.exe HKCUSoftwareClasses.pdf"





                                                              share|improve this answer














                                                              I'm not sure the tool ExecElevated.exe (13KB) will do the job....but it might.
                                                              Or at least be useful for others with similar needs who came to this page as I did (but I didn't find the solution so I ended up creating the tool myself in .Net).



                                                              It will execute an application with elevated token (in admin mode).
                                                              But you will get an UAC dialog to confirm! (maybe not if UAC has been disabled, haven't tested it).



                                                              And the account calling the tool must also have admin. rights of course.



                                                              Example of use:



                                                              ExecuteElevated.exe "C:Utilityregjump.exe HKCUSoftwareClasses.pdf"






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Oct 18 at 22:58

























                                                              answered Nov 14 '14 at 23:55









                                                              MrCalvin

                                                              549510




                                                              549510








                                                              • 2




                                                                I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                                – Giridhar Karnik
                                                                Apr 12 '15 at 15:51








                                                              • 1




                                                                link is broken.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:39










                                                              • Link reestablished, sorry for that
                                                                – MrCalvin
                                                                Oct 18 at 22:59














                                                              • 2




                                                                I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                                – Giridhar Karnik
                                                                Apr 12 '15 at 15:51








                                                              • 1




                                                                link is broken.
                                                                – Dzmitry Lahoda
                                                                Oct 14 at 6:39










                                                              • Link reestablished, sorry for that
                                                                – MrCalvin
                                                                Oct 18 at 22:59








                                                              2




                                                              2




                                                              I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                              – Giridhar Karnik
                                                              Apr 12 '15 at 15:51






                                                              I just love the answers with "This might work haven't tested yet", and of course the one with "not sure"....
                                                              – Giridhar Karnik
                                                              Apr 12 '15 at 15:51






                                                              1




                                                              1




                                                              link is broken.
                                                              – Dzmitry Lahoda
                                                              Oct 14 at 6:39




                                                              link is broken.
                                                              – Dzmitry Lahoda
                                                              Oct 14 at 6:39












                                                              Link reestablished, sorry for that
                                                              – MrCalvin
                                                              Oct 18 at 22:59




                                                              Link reestablished, sorry for that
                                                              – MrCalvin
                                                              Oct 18 at 22:59










                                                              up vote
                                                              0
                                                              down vote













                                                              I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:



                                                              powershell "start cmd -v runAs"


                                                              This is just a shorter version of user3018703 excellent
                                                              solution:



                                                              powershell -Command "Start-Process cmd -Verb RunAs"





                                                              share|improve this answer

























                                                                up vote
                                                                0
                                                                down vote













                                                                I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:



                                                                powershell "start cmd -v runAs"


                                                                This is just a shorter version of user3018703 excellent
                                                                solution:



                                                                powershell -Command "Start-Process cmd -Verb RunAs"





                                                                share|improve this answer























                                                                  up vote
                                                                  0
                                                                  down vote










                                                                  up vote
                                                                  0
                                                                  down vote









                                                                  I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:



                                                                  powershell "start cmd -v runAs"


                                                                  This is just a shorter version of user3018703 excellent
                                                                  solution:



                                                                  powershell -Command "Start-Process cmd -Verb RunAs"





                                                                  share|improve this answer












                                                                  I don't have enough reputation to add a comment to the top answer, but with the power of aliases you can get away with just typing the following:



                                                                  powershell "start cmd -v runAs"


                                                                  This is just a shorter version of user3018703 excellent
                                                                  solution:



                                                                  powershell -Command "Start-Process cmd -Verb RunAs"






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered 20 hours ago









                                                                  Stiegler

                                                                  166




                                                                  166






















                                                                      up vote
                                                                      -1
                                                                      down vote













                                                                      I did it easily by using this following command in cmd



                                                                      runas /netonly /user:AdministratorAdministrator cmd



                                                                      after typing this command, you have to enter your Administrator password(if you don't know your Administrator password leave it blank and press Enter or type something, worked for me)..






                                                                      share|improve this answer





















                                                                      • did not help me
                                                                        – Dzmitry Lahoda
                                                                        Oct 14 at 6:39















                                                                      up vote
                                                                      -1
                                                                      down vote













                                                                      I did it easily by using this following command in cmd



                                                                      runas /netonly /user:AdministratorAdministrator cmd



                                                                      after typing this command, you have to enter your Administrator password(if you don't know your Administrator password leave it blank and press Enter or type something, worked for me)..






                                                                      share|improve this answer





















                                                                      • did not help me
                                                                        – Dzmitry Lahoda
                                                                        Oct 14 at 6:39













                                                                      up vote
                                                                      -1
                                                                      down vote










                                                                      up vote
                                                                      -1
                                                                      down vote









                                                                      I did it easily by using this following command in cmd



                                                                      runas /netonly /user:AdministratorAdministrator cmd



                                                                      after typing this command, you have to enter your Administrator password(if you don't know your Administrator password leave it blank and press Enter or type something, worked for me)..






                                                                      share|improve this answer












                                                                      I did it easily by using this following command in cmd



                                                                      runas /netonly /user:AdministratorAdministrator cmd



                                                                      after typing this command, you have to enter your Administrator password(if you don't know your Administrator password leave it blank and press Enter or type something, worked for me)..







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Aug 16 at 7:18









                                                                      Harish Regada

                                                                      12




                                                                      12












                                                                      • did not help me
                                                                        – Dzmitry Lahoda
                                                                        Oct 14 at 6:39


















                                                                      • did not help me
                                                                        – Dzmitry Lahoda
                                                                        Oct 14 at 6:39
















                                                                      did not help me
                                                                      – Dzmitry Lahoda
                                                                      Oct 14 at 6:39




                                                                      did not help me
                                                                      – Dzmitry Lahoda
                                                                      Oct 14 at 6:39










                                                                      up vote
                                                                      -4
                                                                      down vote













                                                                      There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user not username:



                                                                      runas /user:machinenameadminuser cmd


                                                                      See relevant help from Microsoft community.






                                                                      share|improve this answer

















                                                                      • 3




                                                                        This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                        – Constantino Cronemberger
                                                                        Apr 14 '15 at 17:57















                                                                      up vote
                                                                      -4
                                                                      down vote













                                                                      There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user not username:



                                                                      runas /user:machinenameadminuser cmd


                                                                      See relevant help from Microsoft community.






                                                                      share|improve this answer

















                                                                      • 3




                                                                        This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                        – Constantino Cronemberger
                                                                        Apr 14 '15 at 17:57













                                                                      up vote
                                                                      -4
                                                                      down vote










                                                                      up vote
                                                                      -4
                                                                      down vote









                                                                      There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user not username:



                                                                      runas /user:machinenameadminuser cmd


                                                                      See relevant help from Microsoft community.






                                                                      share|improve this answer












                                                                      There are several ways to open an elevated cmd, but only your method works from the standard command prompt. You just need to put user not username:



                                                                      runas /user:machinenameadminuser cmd


                                                                      See relevant help from Microsoft community.







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Sep 30 '13 at 16:05









                                                                      Matt

                                                                      80121228




                                                                      80121228








                                                                      • 3




                                                                        This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                        – Constantino Cronemberger
                                                                        Apr 14 '15 at 17:57














                                                                      • 3




                                                                        This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                        – Constantino Cronemberger
                                                                        Apr 14 '15 at 17:57








                                                                      3




                                                                      3




                                                                      This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                      – Constantino Cronemberger
                                                                      Apr 14 '15 at 17:57




                                                                      This is not the same thing as running an elevated command, because when I open an elevated cmd window and I type "whoami" it brings the same result as a non elevated window. When I run "whoami /all" in both cases I can see the differences in terms of permissions for the very same user.
                                                                      – Constantino Cronemberger
                                                                      Apr 14 '15 at 17:57










                                                                      up vote
                                                                      -4
                                                                      down vote













                                                                      I used runas /user:domainuser@domain cmd which opened an elevated prompt successfully.






                                                                      share|improve this answer





















                                                                      • It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                        – brokenthorn
                                                                        Nov 20 '14 at 8:28















                                                                      up vote
                                                                      -4
                                                                      down vote













                                                                      I used runas /user:domainuser@domain cmd which opened an elevated prompt successfully.






                                                                      share|improve this answer





















                                                                      • It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                        – brokenthorn
                                                                        Nov 20 '14 at 8:28













                                                                      up vote
                                                                      -4
                                                                      down vote










                                                                      up vote
                                                                      -4
                                                                      down vote









                                                                      I used runas /user:domainuser@domain cmd which opened an elevated prompt successfully.






                                                                      share|improve this answer












                                                                      I used runas /user:domainuser@domain cmd which opened an elevated prompt successfully.







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Mar 10 '14 at 23:02









                                                                      JasonC

                                                                      115




                                                                      115












                                                                      • It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                        – brokenthorn
                                                                        Nov 20 '14 at 8:28


















                                                                      • It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                        – brokenthorn
                                                                        Nov 20 '14 at 8:28
















                                                                      It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                      – brokenthorn
                                                                      Nov 20 '14 at 8:28




                                                                      It requires the credentials of another user. If you're already Administrator and want to run with elevated privileges like when you right click an application and choose run as administrator and no password is requested, just a confirmation dialog, then you need something else. I came here searching for that answer but doesn't seem to be here.
                                                                      – brokenthorn
                                                                      Nov 20 '14 at 8:28


















                                                                       

                                                                      draft saved


                                                                      draft discarded



















































                                                                       


                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function () {
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19098101%2fhow-to-open-an-elevated-cmd-using-command-line-for-windows%23new-answer', 'question_page');
                                                                      }
                                                                      );

                                                                      Post as a guest




















































































                                                                      Popular posts from this blog

                                                                      Bressuire

                                                                      Vorschmack

                                                                      Quarantine