Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for email.bat

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

  1. @ECHO OFF
  2. SET ERRORS=0
  3. :: Use your own mappings and search strings here
  4. NET USE P: | FIND /I "%username%" >NUL 2>NUL
  5. IF ERRORLEVEL 1 CALL :ErrorMsg P:
  6. NET USE S: | FIND /I "system" >NUL 2>NUL
  7. IF ERRORLEVEL 1 CALL :ErrorMsg S:
  8. :: Create an e-mail message if any errors were detected
  9. IF %ERRORS% GEQ 1 CALL :Mail
  10. :: Clear variables used in this batch file
  11. FOR %%A IN (BODY DATE ERRORS LINE MESSAGE TIME) DO SET %%A=
  12. GOTO :EOF
  13.  
  14. :ErrorMsg
  15. SET /A ERRORS = %ERRORS% + 1
  16. NET USE %1 >NUL 2>NUL
  17. IF ERRORLEVEL 1 (
  18. 	SET BODY=%BODY%%%0D%%0ADrive%%20%1%%20not%%20mapped
  19. 	GOTO :EOF
  20. )
  21. FOR /F "TOKENS=3* DELIMS= " %%A IN ('NET USE %1 ^| FIND "Local name"') DO SET MESSAGE=Drive%%20%%A%%20mapped%%20to%%20
  22. :: Replacement of backslashes "\" by "%%5C"
  23. :: prevents interpretation of "\n" as CR/LF
  24. FOR /F "TOKENS=3,4* DELIMS=\ " %%A IN ('NET USE %1 ^| FIND "Remote name"') DO SET MESSAGE=%MESSAGE%%%5C%%5C%%A%%5C%%B
  25. SET BODY=%BODY%%%0D%%0A%MESSAGE%
  26. GOTO :EOF
  27.  
  28. :Mail
  29. FOR /F "TOKENS=2*" %%A IN ('DATE/T') DO SET DATE=%%A
  30. FOR /F %%A IN ('TIME/T') DO SET TIME=%%A
  31. START mailto:helpdesk@ourdomain.com?subject=Drive%%20mapping%%20error^&body=At%%20%DATE%,%%20%TIME%,%%20user%%20%USERNAME%%%20encountered%%20the%%20following%%20drive%%20mapping%%20error(s)%%20on%%20%COMPUTERNAME%:%%0D%%0A%BODY%
  32. GOTO :EOF
  33.  

page last uploaded: 2016-12-15, 11:20