Jump to content
Sign in to follow this  
Tumulus

Use Elevated CMD

Recommended Posts

Tumulus

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?

RunAs("administrator",@ComputerName,$sAdminPassword,0,@ComSpec)
    Sleep (500)

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

    Send("Y")
    Send("{ENTER}")

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

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

    WinClose("C:\Windows\system32\cmd.exe")

 

Share this post


Link to post
Share on other sites
JLogan3o13

@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
AdamUL

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

 

Adam

Share this post


Link to post
Share on other sites
Tumulus

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? 

RunAs("administrator",@ComputerName,$sAdminPassword,0,@ComSpec)

 

Share this post


Link to post
Share on other sites
AdamUL

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.  

 

 

Adam

Share this post


Link to post
Share on other sites
Tumulus

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
AdamUL

Your welcome.  I'm glad I could help.  

 

Adam

 

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

    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
×