Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for admingrp.bat

(view source code of admingrp.bat as plain text)

  1. @echo off 
  2. cls
  3. :: ADMINGRP.BAT
  4. ::
  5. :: Author - Kenneth C. Mazie
  6. :: Kaiser Permanente National Server Operations - Walnut Creek, Ca
  7. :: Date - 11-29-2000
  8. :: Version - 3.0
  9. ::
  10. :: This batch file is intended to remotely update the local administrators group on selected Windows NT
  11. :: machines in a domain.  It can be altered to do othe things with a minimum of difficulty but it was 
  12. :: written to update group membership.  The batch requires the USERTOGRP.EXE utility from the NT resource
  13. :: kit.  Some variables must be set prior to the first run, this includes the domain, admin password, 
  14. :: admin account name, group or user to add (user variable), and the group to add to.  
  15.  
  16. :: Process flow: The batch reads the domain and checks each entry against an exclusion file called 
  17. :: "EXCLUDE.TXT".  The exclusion file is a flat text file that must reside in the same folder as this 
  18. :: batch.  It conatins one entry per line and each entry should the name of a machine to bypass.  The 
  19. :: last line in the exclusion file should be simply "The" since that is the last line outputed by the 
  20. :: NET VIEW command. If the current machine is NOT one of the exclusion entries the group membership gets 
  21. :: processed.  The process subroutine can be altered to perform anything you like on the remote PC like 
  22. :: copy files or if SU is loaded other administrative operations can be done.  All actions are captured 
  23. :: in a log file located in the same folder as this batch.  The one exception being off-line machines
  24. :: which echo four error lines to the screen.   Note that the match variable preset should not be changed.
  25.  
  26. :: This batch is intended to be run on Windows NT.
  27. ::----------------------- batch code -----------------------
  28.  
  29. :variables
  30. :: set all initial variables here
  31. set user=domain desktop support
  32. set group=Administrators
  33. set password=
  34. set domain=
  35. set admin=administrator
  36. set match=no   
  37.  
  38.  
  39. :getdate
  40.   FOR /F "TOKENS=1,2*" %%A IN ('DATE/T') DO SET TODAY=%%B
  41.   SET TODAY=%TODAY:/=-%
  42.   echo This run completed on %TODAY% >.\log.txt
  43.   ::ren .\log.txt .\%TODAY%-log.txt
  44.  
  45. :getmachines
  46.   FOR /F "skip=3 tokens=*" %%A IN ('NET VIEW /DOMAIN:%domain%') DO CALL :check %%A
  47.   goto exit
  48.  
  49. :check
  50.   set currentmachine=%1
  51.   for /F %%i in (.\exclude.txt) do if %currentmachine%==%%i set match=yes
  52.   if %match%==no call :process
  53.   if %match%==yes call :bypass
  54.   goto :EOF
  55.   goto :EOF
  56.   goto :exit 
  57.  
  58. :bypass 
  59.   @echo Current system: %currentmachine% is on the exclude list, BYPASSING....... >>.\log.txt
  60.   echo -===================================->>.\log.txt
  61.   set match=no
  62.   goto :EOF
  63.  
  64. :process
  65.   @echo Current system: %currentmachine% is valid......Processing....... >>.\log.txt
  66.   if exist .\temp.txt del /F /Q .\temp.txt
  67.   echo domain: %currentmachine%>> .\temp.txt
  68.   echo localgroup: %group%>> .\temp.txt
  69.   echo %User%>> .\temp.txt
  70.  
  71.   echo %currentmachine%
  72.   net use \\%currentmachine%\IPC$ /D 
  73.   net use \\%currentmachine%\IPC$ /USER:%domain%\%admin% %password% >>.\log.txt
  74.  
  75.   Usrtogrp.exe .\temp.txt >>.\log.txt
  76.   echo -===================================->>.\log.txt
  77.   set match=no
  78.   goto :EOF
  79.  
  80. :Exit
  81.  

page last modified: 2024-04-16; loaded in 0.0100 seconds