Sign in to follow this  
Followers 0
mbkowns

RUN() multiple in same CMD window no BATCH

5 posts in this topic

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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

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  
Followers 0