Jump to content
Sign in to follow this  

Use Elevated CMD

Recommended Posts


I need to create a new administrator account on a number of computers, so figured I would make a script to do it. 

You can only add/modify admin profile from an elevated command prompt (administrator command prompt). So I tried writing that into my short script. I thought that my "RunAs" command below would do the trick, but it opens a standard cmd window through the admin profile.

Anyone able to tell me how to get it to open the elevated cmd?

    Sleep (500)

    Send("net user /ADD " & $sUsername & " " & $sPassword)


    Send("net user " & $sUsername & " /passwordchg:no")

    Send("net localGroup administrators " & $sUsername & " /ADD")



Share this post

Link to post
Share on other sites

@Tumulus if you are doing this on a "number of computers", why are you not using Active Directory to automate it?

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post

Link to post
Share on other sites

You can use the Local Account UDF to work with local accounts.  Here is an example.  



Share this post

Link to post
Share on other sites

That is a really great question @JLogan3o13. I hadn't even thought to do that. A team lead asked if we could make a script to do it, but it would be much easier in active directory. I'll ask him about that today. 

Also, @AdamUL... That is great! Much easier process for local account management. I can avoid the cmd altogether with those commands right?

However, for the sake of learning, how do I get the cmd to open in an elevated box within an auto it script? We do a lot of scripting and many of our scripts need to operate with administrator permissions. Forgetting the rest of my code (if that is alright), why does this command open a standard cmd window instead of the administrator cmd prompt? 



Share this post

Link to post
Share on other sites

That is correct, you do not need the command window at all.  Also, with the Local Account UDF, you can access remote computers, and setup local accounts.  Just have a look at the function headers.  Also, look in the thread, as other users have submitted other useful functions not included in the UDF.  

RunAs does not give the runas user the Admin Token.  You have to use a workaround to run as a full admin with the Admin Token as a different user.  Here is an example script that shows one way to do it.  The script is wrote to work uncompiled or compiled.  




Share this post

Link to post
Share on other sites

I did the script with the UDF and it was awesome! nifty little scripting there (shout out to @engine for the great work).

The example to run an Admin prompt was really helpful too. I got it working on some other scripts. Thanks again!

Share this post

Link to post
Share on other sites

Your welcome.  I'm glad I could help.  




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Abdulla060
      By Abdulla060
      Hello all, i have about 20 arrays in my script and i need to delete the first element of each, i have the name of the arrays in another array (its used in another part of the script)  and i tried to passing the names to from that array to the _ArrayDelete function but nothing happens and i get an error code :1 which state that i'm trying to delete an array which is not an array
      code example
      #include <Array.au3> global $allarrays[3] = ['array1','array2','array3'] global $array1[3] = ['1', '2', '3'] global $array2[3] = ['1', '2', '3'] global $array3[3] = ['1', '2', '3'] for $i = 0 to UBound($allarrays) - 1 _ArrayDelete($allarrays[$i], 0) Next _ArrayDisplay($array1) obviously i can just use  _arraydelete over and over however i'm looking for a more elegant way of doing this
    • PhoenixPRO
      By PhoenixPRO
      When I try to automate this install program I can not get any of the buttons to click with the "ControlClick" function or any mouse movement to move the mouse to the and click it.  My OS is Windows 10 64Bit.  I have tried both 32bit and 64bit installs of Autoit V3 to no avail.
      I could not even get the run command to start the program until I used the variation of the command below in the script.
      With the script below the install program starts but will not click the "Next" button no matter what I do.
      Any help will be greatly appreciated.
      Thanks in advance.
      #include <MsgBoxConstants.au3>
      Opt("MouseCoordMode", 0) ;1=absolute, 0=relative to active window, 2=client
      Local $Success
      Run(@ComSpec & " /c " & 'C:\PhoenixPro_Install\RDXUtil\RDX_Tools_setup.exe', "C:\PhoenixPro_Install\RDXUtil", @SW_HIDE )

      WinWait("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      WinActivate("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62")
      ControlClick ("RDX Tools 1.62 - InstallShield Wizard", "Welcome to the InstallShield Wizard for RDX Tools 1.62", 1639, "left", 1) ;Next Button
    • Rammanan
      By Rammanan
      Hi all, Below is my script,
      Pls advise me if any wrong on that....File exit in location but the return -1.
      FileOpen($file, 0)
         $line = FileReadLine($file)
      Local $aArray = _FileListToArrayRec($serverpath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
      If @error Then
              MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
          ;_ArrayDisplay($aArray, "Sorted tree")
                 Local $hSearch = FileFindFirstFile($line)
    • Theodoor
      By Theodoor
      I am trying to use the ControlClick in a "save as"-window to select the path of where to save the document.
      I found out that when in press the icon in front of the path, i select the path. So I am trying to press that button (i have attached a print screen of this window).
      While trying to figure out how i had to use the ControlClick, it said somewhere that i could us Au3Info to find out what title,... i should use with the ControlClick.
      The result of the Au3Info I have attached aswel.
      The ControlClick that i tried are these: (and none of these even move the mouse)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32; INSTANCE:4]", "", "1001", "Left" ,1 ,10,10)
      ControlClick("[CLASS:ToolbarWindow32]", "", "", "Left" ,1 ,10,10)
      ControlClick("Save project as", "", "", "Left" ,1 ,10,10)
      I don't know what I am doing wrong.
      Should I use a controlID? is my windowtitle wrong?
      Can anyone help me?
      Thanks in advance,

    • Mercy
      By Mercy
      I need to add a column with data daily at the end of the column and calculate the difference between last two columns in put it in a seperate column. So i need to get the  position of the last column.
      Local $count = $oWorkbook2.Worksheets(1).UsedRange.Columns.Count MsgBox(0,"",$count) ; ***************************************************************************** ; Copy a single cell from another workbook. Pass the source range as object. ; ***************************************************************************** Local $oRange = $oWorkbook2.Worksheets(1).Range("A1:A15") _Excel_RangeCopyPaste($oWorkbook1.Worksheets(1), $oRange,"H1:H15") _Excel_RangeWrite($oWorkbook1, $oWorkbook1.Worksheets(1), "=C2-H2", "I2:I15", False) this code copies to a specific column H with a range 15. But i need to keep that column range to update automatically when columns are added.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.