Jump to content

Help with RunAsWait or RunAs


Briandr
 Share

Recommended Posts

RunAsWait("ADAccount","MYDOMAIN","mypassword",0,@SystemDir & "\net.exe localgroup "& $administrators & " " & chr(34) & $add[$x] & chr(34) & " /add",@SystemDir,@SW_HIDE

Hi,

So what I want to try is use RunAsWait or RunAs to use a different domain account  w/password specified to add a specific domain group to local administrators. I been hunting google and the forums and I think this is close, but I know I am missing something. That something being where I specify the domain group I want added. 

Is there any easier way of doing this? Thanks.

Link to comment
Share on other sites

You can try with something like this :

RunAsWait("ADAccount","MYDOMAIN","mypassword",0, @SystemDir & '\net.exe localgroup "' & $administrators & '" "MYDOMAIN\' & $add[$x] & '" /add')
Link to comment
Share on other sites

Hi,

It saves and compiles fine, but as google only showed me an excerpt from the command I posted I am now getting:

subscript used on non-accessible variable. Any ideas? This is what I have and its not much

#include <File.au3>; File functions
#include <Array.au3>; Array functions
#include <Process.au3>; Array functions
#include <string.au3>

Dim $administrators, $x, $add

RunAsWait("ADAccount","MYDOMAIN","mypassword",0, @SystemDir & '\net.exe localgroup "' & $administrators & '" "MYDOMAIN\MyDomainGroup' & $add[$x] & '" /add')

Not even sure how many of the include statements I need. I am guessing a few can be removed.

Thanks

Edited by Briandr
Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Array.au3>

$AdminName = "ADAdmin"
$AdminPassword = "ADPassword"
$AdminLocal = "Administrators"
$DomainGroup = "Support"
$DomainName = "xyz.com"

RunAsWait("$AdminName","$DomainName","$AdminPassword",2, @SystemDir & @ComSpec & " /c " & "net localgroup & AdminLocal $DomainName\" & $DomainGroup & " /add", @SW_HIDE)

Can someone help? This is testing clean and running without errors so what is wrong with my RunAsWait?

Thanks.

Link to comment
Share on other sites

In your example script in post #3 you declared $add as a variable but tried to access it as an array which caused that error to show up.

In your post in #4, your variables are enclosed in quotes, so they're seen as strings and not as variables, and you aren't accessing the contents of the variables that way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yes, don't use @SystemDir and @Comspec together. @Comspec already points to the system32 folder, so adding it to the start of @ComSpec just points to the wrong place. Plus, @SystemDir doesn't end in a trailing backslash, so even if @ComSpec didn't point to the system32 folder already, your path would be wrong.

Also, never ever ever use /c and @SW_HIDE in a run command until you know that it works. Using those 2 together in an untested line will leave you clueless as to what isn't working and why. /c closes the command window after the command runs, and @SW_HIDE hides the window to start with, so you're never going to see any errors in the command window.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I took all of your suggestions but the command window is not opening when I run the exe. Frustrating as I can't see where this is failing

RunAsWait("$AdminName","$DomainName","$AdminPassword",2, @ComSpec & "net localgroup & $AdminLocal $DomainName\" & $DomainGroup & " /add")

I

Edited by Briandr
Link to comment
Share on other sites

Try with @ComSpec & " /c net localgroup...."

edit : and remove the quotes arround the variables :.

RunAsWait($AdminName, $DomainName, $AdminPassword, 2, @ComSpec & ' /c net localgroup "' & $AdminLocal & '" "' & $DomainName & '\' & $DomainGroup & '" /add')
Edited by jguinch
Link to comment
Share on other sites

Hi jguinch, 

Thanks for the help yesterday and today. I am seeing a command window now, but it is opening and closing really fast. Can't examine the message, but it is failing. I had looked into using " /k " as oppposed to " /c ". I see your example has /c, which BrewMan thought would not help in the troubleshooting process. 

Since this is a relatively small and straight forward autoit, do I need to look into a STDOUT function to get the command output? I am hoping we can keep it as simple as possible. The other thing I added today was #RequireAdmin. Maybe an explanation is needed. A domain joined computer logged in as local adminstrators needs to use credentials from a domain account to add a domain group to the local adminstrators. Which is why my RunAsWait is laid out this way. Hope this helps as being vague stinks. Maybe you guys already figured that out. Just wanted to mention it.

Edited by Briandr
Link to comment
Share on other sites

RunAsWait($AdminName, $DomainName, $AdminPassword, 2, @ComSpec & ' /c echo net localgroup "' & $AdminLocal & '" "' & $DomainName & '\' & $DomainGroup & '" /add') 

I did as you suggested and the command window opened and closed. I did  not wrap echo in ' ' or " ". Perhaps that is needed. I will keep researching this work, but I do appreciate the assistance

Link to comment
Share on other sites

Output is:

net localgroup "Administrators" "mydomainMyGroup" /add

I just have a feeling that the command is not executing with the account and password I specified either due to syntax error or lack of permissions (I am looking into permissions issue on the account)

Link to comment
Share on other sites

Using echo won't execute the command, it only displays it in the console window, which jguinch told you would happen. It was suggested so that you can see if your command line is written correctly.

You need to learn how to use the command console, because it's quite obvious you have no idea what half of what you're typing even does.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If the command showed in the output (post #14) works, you just have to remove echo. You can keep /k for the moment, it allows you to see the result. If the result is OK, you will just have to replace /k by /c.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...