Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for 4allmembers.bat

(view source code of 4allmembers.bat as plain text)

  1. @ECHO OFF
  2. VER | FIND "Windows 2000" >NUL
  3. IF ERRORLEVEL 1 GOTO Syntax
  4.  
  5. SETLOCAL ENABLEEXTENSIONS
  6.  
  7. :: Parameter check
  8. IF [%2]==[] (
  9. 	ENDLOCAL
  10. 	GOTO Syntax
  11. )
  12.  
  13. SET Group=
  14. SET Domain=
  15. NET GROUP %1 /DOMAIN >NUL 2>NUL
  16. IF NOT ERRORLEVEL 1 (
  17. 	SET Group=GROUP
  18. 	SET Domain=/DOMAIN
  19. )
  20. NET GROUP %1 >NUL 2>NUL
  21. IF NOT ERRORLEVEL 1 (
  22. 	SET Group=GROUP
  23. 	SET Domain=
  24. )
  25. NET LOCALGROUP %1 /DOMAIN >NUL 2>NUL
  26. IF NOT ERRORLEVEL 1 (
  27. 	SET Group=LOCALGROUP
  28. 	SET Domain=/DOMAIN
  29. )
  30. NET LOCALGROUP %1 >NUL 2>NUL
  31. IF NOT ERRORLEVEL 1 (
  32. 	SET Group=LOCALGROUP
  33. 	SET Domain=
  34. )
  35. IF NOT DEFINED Group (
  36. 	ECHO.
  37. 	ECHO "%~1" is not a valid NT group
  38. 	ENDLOCAL
  39. 	GOTO Syntax
  40. )
  41.  
  42. :: Main command
  43. FOR /F "skip=8 tokens=* delims=" %%A IN ('NET %Group% %1 %Domain% ^| FIND /V "The command"') DO FOR /F "tokens=1-3 delims=	 " %%a IN ('ECHO.%%A') DO (
  44. 	CALL :Command "%%a" %*
  45. 	IF NOT "%%b"=="" CALL :Command "%%b" %*
  46. 	IF NOT "%%c"=="" CALL :Command "%%c" %*
  47. )
  48. ENDLOCAL
  49. GOTO End
  50.  
  51.  
  52. :Command
  53. SETLOCAL
  54. SET User$=%~1
  55. SHIFT
  56. :Loop
  57. SHIFT
  58. IF [%1]==[] GOTO Continue
  59. IF [%1]==[ ] GOTO Continue
  60. IF [%~1]==[#] (SET command$=%command$% %User$%) ELSE (SET command$=%command$% %1)
  61. GOTO Loop
  62. :Continue
  63. IF "%command$%"==" " GOTO Syntax
  64. CALL %command$%
  65. ENDLOCAL
  66. GOTO:EOF
  67.  
  68.  
  69. :Syntax
  70. ECHO.
  71. ECHO 4AllMembers,  Version 2.11 for Windows 2000
  72. ECHO Execute a command once for each member of a local, domain local or global group
  73. ECHO Written by Rob van der Woude
  74. ECHO http://www.robvanderwoude.com
  75. ECHO.
  76. IF "%OS%"=="Windows_NT" ECHO Usage:  %~n0  ^<group_name^>  ^<any_command^>  [ ^<parameters^> ]
  77. IF NOT "%OS%"=="Windows_NT" ECHO Usage:  4AllMembers  {group_name}  {my_command}  [ {parameters} ]
  78. ECHO.
  79. ECHO Any_command will be executed once for each member of group_name
  80. ECHO Command line parameter(s) "#" will be substituted by user ID
  81.  
  82. :End
  83.  

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