Sign in to follow this  
Followers 0
freddykid

Multiple Domains/local admins loop

4 posts in this topic

#1 ·  Posted (edited)

I have a Annual sales meeting coming up and I have been working on an automated system maintenance, clean up and install some reporting software and such. We are servicing three different domain's users and each domain has a different local admin account. So for the maintenance to function correctly the user will need Admin rights. So I have a username prompt and the use the @logondomain macro to get which domain they belong too. I am using the runaswait function to run a net command to add them as an admin. My problem may be syntax or the way I am formating the strings, I honestly spent 5 hours just on this part of the script and am stuck. Everything after this portion runs fine once the user has admin rights. I am hoping someone can help cure my insanity or show me a better way to do this.

While 1
            If Not IsDeclared("sInputBoxAnswer") Then Dim $sInputBoxAnswer ; Prompt for Technician
            $sInputBoxAnswer = InputBox("Domain Username","Enter your PC login account (ex. Tsmith): ","" & @UserName," ","300","150","555","555");Default autofill with current logon name.
                Select
                Case @Error = 0 ;OK and the string returned is valid
                    If $sInputBoxAnswer <> "" Then ExitLoop
                Case @Error = 1 ;Cancel button was pushed
                    Exit
                Case @Error = 3 ;Timeout
                    Exit
                EndSelect
WEnd

While not IsAdmin() 
        
    $domain1 = String("Microsoft") 
    $domain2 = string("Contoso")
    $domain3 = string("fabricam")
    $domain = String(@LogonDomain)
;$compname = String(@Computername)
    MsgBox(0, "Domain","" &$domain & @LF & $domain1 &@lf & $domain2 &@lf & $domain3, 15); show me how they are populated for debugging
    $result1 = StringCompare ($domain, $domain1 ) 
    
    $result2 = StringCompare ($domain, $domain2 )
    
    $result3 = StringCompare ($domain, $domain3)
        
        Select ;This will Select will add user to the local admin group based on their domain using thier local Admin account.
            Case $result1 = 0   ;String is the same
                        
                $result4 = runaswait ("admin1",@ComputerName, "Password1",1,  @ComSpec & 'net localgroup administrators microsoft\'&$sInputBoxAnswer &' /ADD', @SW_SHOW); insert the name typed by the Technician 
                    if @error <> 0 then 
                    MsgBox(0, "Attemp to add", "Action Failed " & $result4, 10)
                    FileWrite(@ComputerName&".txt", @CRLF & "really you suck at scripting "&$sInputBoxAnswer &@CRlf)
                    Exit
                    EndIf
            Case $result2 = 0   
                runaswait ("admin2", @ComputerName, "Password2",@ComSpec & 'NET LOCALGROUP administrators contoso\' & $sInputBoxAnswer & ' /ADD', @SystemDir, @SW_HIDE);insert the name typed by the Technician 
            Case $result3 = 0 
                RunAsWait ("admin3", @ComputerName, "Password3",@ComSpec & 'NET LOCALGROUP administrators fabricam\' & $sInputBoxAnswer & ' /ADD', @SystemDir, @SW_HIDE);insert the name typed by the Technician 
        EndSelect
WEnd
Edited by freddykid

Share this post


Link to post
Share on other sites



The return value of IsAdmin() will not change while the script is running. After being added to a group, the user must logout/login to pick up the additional token for that group membership.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The issue was a syntax issue that I finally worked out. I removed @comspec and then specified the working Dir... even though it should have defaulted there.

Old not working

$result4 = runaswait ("admin1",@ComputerName, "Password1",1,  @ComSpec & 'net localgroup administrators microsoft\'&$sInputBoxAnswer &' /ADD', @SW_SHOW)

Working syntax

$result4 = RunAsWait ('admin1',@ComputerName, 'Password1','', 'NET LOCALGROUP administrators microsoft\'&$sInputBoxAnswer & ' /add', @SystemDir); insert the name typed by the Technician

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The return value of IsAdmin() will not change while the script is running. After being added to a group, the user must logout/login to pick up the additional token for that group membership.

:)

Thanks for the reply, Yeah sorry I tried to keep this as short as possible in the area I had a problem with. But once the "net localgroup" @error = 0 I exit the loop and force logoff.

if @error <> 0 then 
    MsgBox(0, "Attemp to add", "Action Failed ", 10)
    Exit
ElseIf @error = 0 then 
    ExitLoop

Wend

MsgBox (0, "", "Please logoff and Re-run the ASM script again...Logging off in 15 seconds.",15); If the user did not have Admin Rights then the script forces a logoff.
RunWait ("Shutdown.exe -l -f",@SystemDir, @SW_SHOW)

This is nested in another loop which checks prior if the user is an admin.if they are it skips this whole part.

Edited by freddykid

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