Article ID: 180546
Article Last Modified on 2/27/2007
INSUSER.BAT, SUB1.BAT, SUB2.BAT, SUB3.BAT, SUB4.BAT,
SUB5.BAT, and ADDUSERS.DAT.
set CurrentDomain=mydomain echo off cls if (%CurrentDomain%) == (mydomain) echo Edit the first line of INSUSER.BAT. if (%CurrentDomain%) == (mydomain) echo then rerun INSUSER.BAT if (%CurrentDomain%) == (mydomain) goto verybottom if not exist addusers.dat goto DisplayAddUsers rem *** Display current variable settings *** echo Current domain is %CurrentDomain%. echo. rem *** Determine if working list is present *** If exist working.txt echo Working list detected, resuming batch process. If exist working.txt goto SkipCreateList echo Creating a list of member servers in %CurrentDomain%. echo. netdom /d:%CurrentDomain% member > working.txt rem *** Remove NETDOM formatting from server names *** if exist temp.txt del temp.txt for /F "skip=6 delims=\ tokens=2" %%a in (working.txt) do call sub1.bat %%a del working.txt ren temp.txt working.txt :SkipCreateList rem *** Determine if machine is online *** if exist online.txt del online.txt for /F "delims=\\ tokens=1" %%a in (working.txt) do call sub2.bat %%a rem *** Remove servers that have been processed from WORKING.TXT *** if not exist online.txt goto NoServersOnline echo. echo Updating list of servers that need to be processed. for /F "delims= tokens=1" %%a in (online.txt) do call sub4.bat %%a echo List complete. goto Bottom :DisplayAddUsers Echo. Echo. You must modify the contents of ADDUSERS.DA, then rename the Echo. file to ADDUSERS.DAT. Then re-run this batch file. goto verybottom :NoServersOnline Echo. Echo There are no servers currently online that can be processed. :Bottom echo. echo ------------------------------------ echo --- Finished processing servers. --- echo ------------------------------------ :verybottom
rem *** Remove formatting from Netdom output *** echo %1 >> temp.txt
echo Pinging %1... ping %1 > PING.TXT for /F "skip=6 tokens=4" %%a in (PING.TXT) do call sub3.bat %%a %1 del PING.TXT
rem *** If server is online it will be logged in online.txt for ***
rem *** processing later. ***
rem *** %2 is a bogus variable, thrown away.
if not (%1) == (bytes) goto NotOnline
echo %3 >> ONLINE.TXT
echo [%3 is online.]
rem ***********************************************
rem *** Put per-server processing commands here ***
rem ***********************************************
rem *** The following section determines if *******
rem *** Workstation or Server is running *******
rem ***********************************************
REM Next Line wrapped by text editor for readability, it should all be on one line
for /F "delims= tokens=3" %%i IN ('reg query hklm\system\currentcontrolset\control\ProductOptions\ProductType \\%3') DO set product_type=%%i
REM End single line
if "%product_type%"=="" goto Undetermined
if "%product_type%"=="WinNT" goto Workstation
if "%product_type%"=="ServerNT" goto Server
if "%product_type%"=="LanmanNT" goto DomainController
:Undetermined
echo Unable to determine Windows NT Product Type, check the following
echo registry key for product type
echo.
echo hklm\system\currentcontrolset\control\ProductOptions\ProductType
echo.
echo Expected values
echo.
echo ProductType Product
echo ----------------------------------------------------
echo WinNT Windows NT Workstation is running
echo ServerNT Windows NT Server is running
echo LanmanNT Windows NT Domain controller
echo.
echo %3 >>undetermined.txt
goto Sub3bot
:DomainController
echo %3 >>dc.txt
goto sub3bot
:Server
echo %3 is a Server, skipping...
echo %3 >>server.txt
goto adduser
:Workstation
echo %3 is a Workstation, processing %3
echo %3 >> wks.txt
goto adduser
:adduser
ECHO Adding new user to local administrators group on %3.
ECHO *** \\%3 *** >> local.log
rem Add a user to each member servers local administrators group
ADDUSERS \\%3 /C addusers.dat > nul
rem *****************************************************
rem net send %3 "it worked"
rem *** Put per-server processing commands above here ***
rem *****************************************************
goto Sub3Bot
:NotOnline
:Sub3Bot
Filename: SUB4.BAT
rem *** loop thru each name in working.txt and remove servers that were *** rem *** in online.txt. *** echo Removing %1 from list. if exist temp.txt del temp.txt for /F "tokens=1" %%a in (working.txt) do call sub5.bat %%a %%1 del working.txt if exist temp.txt ren temp.txt working.txt
rem *** Filter out servers that have been updated *** rem %1 is name from working.txt rem %2 is name from online.txt if (%1) == (%2) echo %1 >> complete.txt if not (%1) == (%2) echo %1 >> temp.txt
[Local] Administrators,Members can fully administer the computer,<domain\user>,
rem *** If server is online it will be logged in online.txt for ***
rem *** processing later. ***
rem *** %2 is a bogus variable, thrown away.
if not (%1) == (bytes) goto NotOnline
echo %3 >> ONLINE.TXT
echo [%3 is online.]
rem ***********************************************
rem *** Put per-server processing commands here ***
rem ***********************************************
rem *** The following section determines if *******
rem *** Workstation or Server is running *******
rem ***********************************************
REM Next Line wrapped by text editor for readability, it should all be on
one line
for /F "tokens=3" %%i IN ('reg query
hklm\system\currentcontrolset\control\ProductOptions\ProductType \\%3') DO
set product_type=%%i
REM End single line
if "%product_type%"=="" goto Undetermined
if "%product_type%"=="WinNT" goto Workstation
if "%product_type%"=="ServerNT" goto Server
if "%product_type%"=="LanmanNT" goto DomainController
:Undetermined
echo Unable to determine Windows NT Product Type, check the following
echo registry key for product type
echo.
echo hklm\system\currentcontrolset\control\ProductOptions\ProductType
echo.
echo Expected values
echo.
echo ProductType Product
echo ----------------------------------------------------
echo WinNT Windows NT Workstation is running
echo ServerNT Windows NT Server is running
echo LanmanNT Windows NT Domain controller
echo.
echo %3 >>undetermined.txt
goto Sub3bot
:DomainController
echo %3 >>dc.txt
goto sub3bot
Keywords: kbinfo KB180546