LISTING 3: The Addthem Routine :: Determine whether the Administrators group exists. Set Error= :: BEGIN CALLOUT A For /f "tokens=*" %%i in ('Local administrators \\%target% ^|Find /i "GetUsers"') Do (Set error=%%i) & (Goto :Error) For /f "tokens=*" %%i in ('Local administrators \\%target% ^|find /i "found."') Do (Set error=%%i) & (Goto :Error) :: END CALLOUT A :Error If Defined Error (Echo %target%,,,,X,%User%,>>%Log%) & (Set /a Errorcntr+=1) & (Goto :Next1) :: Determine whether the HelpDesk group exists in the Administrators group. Set Error= :: BEGIN CALLOUT B For /f "tokens=*" %%i in ('Local administrators \\%target% ^|Find "%Group%"') Do (Set Result=%%i) :: END CALLOUT B :: If the HelpDesk group exists, jump to the :Next1 code. If Defined Result (Echo %target%,X,,,,%User%,>>%Log%) & (Echo Group already added) & (Set /a Alreadycntr+=1) & (Goto :Next1) Echo Attempting to add group now. :: BEGIN CALLOUT C :: Create the Addusers input file. Echo [Local]>%temp%\addusr.txt Echo Administrators,Members can fully administer the computer/domain,%Group%>>%temp%\addusr.txt :: END CALLOUT C :: BEGIN CALLOUT D :: Use the Addusers utility to add the HelpDesk group. addusers /c %temp%\addusr.txt \\%target% :: END CALLOUT D :: Check again to see whether the HelpDesk group exists. Set Result= For /f "tokens=*" %%i in ('Local administrators \\%target% ^|find "%Group%"') Do (Set result=%%i) :: If the HelpDesk group exists, write to the log, display a message :: that notes the successful addition, and increment the Add counter. If Defined Result (Echo %target%,,X,,,%User%,>>%Log%) & (Echo Group added successfully.) & (Set /a Addcntr+=1) & (Goto :Next1) :: If the HelpDesk group doesn’t exist, write to the log, display an :: error message, and increment the Error counter. (Echo %target%,,,,X,%User%,>>%Log%) & (Echo Group addition error being written to log.) & (Set /a Errorcntr+=1) :Next1 Net Use \\%target%\ipc$ /d 1>NUL 2>NUL :Last Goto :EOF