Jump to content

RUN() multiple in same CMD window no BATCH


Recommended Posts

Is it possible to run multiple things in the same command window without having to run a batch file? I have many admins that need to get removed as part of a larger script but I would like instead of a CMD window created for each that one could be opened and execute multiple lines.

RunWait("net localgroup administrators " & '"domain\siteadmin1"' & " /delete", "",@SW_HIDE)

RunWait("net localgroup administrators " & '"domain\siteadmin2"' & " /delete", "",@SW_HIDE)

RunWait("net localgroup administrators " & '"domain\siteadmin3"' & " /delete", "",@SW_HIDE)

RunWait("net localgroup administrators " & '"domain\siteadmin12"' & " /delete", "",@SW_HIDE)

RunWait("net localgroup administrators " & '"domain\siteadmin22"' & " /delete", "",@SW_HIDE)

RunWait("net localgroup administrators " & '"domain\siteadmin78" & " /delete", "",@SW_HIDE)

more need to be remove just an example.

Let me know if that is possible. Work around now would be to fileinstall() batch file to c:\ and delete it after it is run but it would be nice if this worked without having to do that.

thanks

Link to comment
Share on other sites

As the windows are hidden, I don't see a problem with multiple calls ... just make a function so that it is easier to code... is there speed or something that concerns you?

DeleteDomUser("domain\siteadmin2")
DeleteDomUser("domain\siteadmin3")
DeleteDomUser("domain\siteadmin4")
DeleteDomUser("domain\siteadmin5")
DeleteDomUser("domain\siteadmin6")

Func DeleteDomUser($user)
   RunWait("net localgroup administrators " & $user & " /delete", "",@SW_HIDE)
EndFunc

Lar.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

You could also try something like -

#include "Constants.au3"

Dim $line

$pid = Run("cmd", "", "", $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($pid, "dir" & @CRLF)
StdinWrite($pid, "exit" & @CRLF)
While 1
    $line = $line & StdoutRead($pid)
    If @error Then ExitLoop
WEnd
MsgBox(0, "Stdout", $line)
ProcessClose($pid)
Exit
Edited by wraithdu
Link to comment
Share on other sites

If you really want to "stack" a bunch of commands, you can use && to separate them and it will run them in sequence.

For example.

Open a CMD prompt and type in 'ipconfig && dir c:\ && echo "My Hostname Is" && hostname' (no single quotes)

But there isn't anything wrong with Larry's idea of making a function. You could even make an array of "userids" and loop through it call the DelDomUser func.

Edited by spudw2k
Link to comment
Share on other sites

Thanks for the quick help. It doesn't take very long to do it even doing ones that don't exist.

went with this while I was waiting like all the other ideas might change to those as well.

Func _RemoveAllAdmins()
    For $rAdmin = 0 To 9
        $zrAdmin = "0" & $rAdmin
        RunWait("net localgroup administrators " & '"67-nis\sitealtirisadmin' & $zrAdmin & '"' & " /delete", "", @SW_HIDE)
        RunWait("net localgroup administrators " & '"67-nis\sitepcadmin' & $zrAdmin & '"' & " /delete", "", @SW_HIDE)
    Next

    For $rAdmin = 10 To 100
        RunWait("net localgroup administrators " & '"67-nis\sitealtirisadmin' & $rAdmin & '"' & " /delete", "", @SW_HIDE)
        RunWait("net localgroup administrators " & '"67-nis\sitepcadmin' & $rAdmin & '"' & " /delete", "", @SW_HIDE)
    Next
EndFunc  ;==>_RemoveAllAdmins
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...