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