Share Pastebin
Guest
Public paste!

mixty

By: a guest | Nov 4th, 2009 | Syntax: DOS | Size: 2.15 KB | Hits: 131 | Expires: Never
Copy text to clipboard
  1. @echo off & setlocal enabledelayedexpansion
  2.  
  3. :: ****************************************************************
  4. :: Batch: Remote File Existence Check
  5. :: Creation Date: 4th Nov 2009
  6. :: By: mixty dot hk at gmail dot com
  7. :: Supported OS: 2K/XP/Vista/7
  8. :: Description: This batch checks a specified list of computers for
  9. ::              specified files. It outputs a specified .CSV file
  10. ::              containing "Computer Name","Result"
  11.  
  12. ::              "Result" can be any of the following:
  13. ::              "Yes" -- All files are found
  14. ::              "No" -- One/all of the file is/are not found
  15. ::              "Error" -- Error mapping network drive
  16.  
  17. ::              Ensure you're running this as a domain administrator
  18. ::              or a user with enough access right to any specified
  19. ::              computers' admin$ share.
  20.  
  21. :: Usage: See below
  22. :: ****************************************************************
  23.  
  24. :: specify a file containing computer (names or IP), one on each line
  25. set compFile=c:\computers.txt
  26.  
  27. :: specify output file
  28. set output=c:\results.csv
  29.  
  30. :: specify error log
  31. set error=c:\error.log
  32.  
  33. :: specify a drive to be mapped (must be unused locally)
  34. set tempDrive=x:
  35.  
  36. :: specify 2 files to check for existence
  37. set file1=Thawbrkr.dll
  38. set file2=kbdurdu.dll
  39.  
  40. :: specify the remote share to be connected
  41. :: e.g. where the files to be checked reside
  42. set share=admin$\system32
  43.  
  44. :: specify any additional parameter for NET USE (default: empty)
  45. set anyParameter=
  46.  
  47. type nul>%error%
  48. echo "Computer Name","Results">"%output%"
  49. net use %tempDrive% /del /y>>nul 2>>&1
  50.  
  51. for /f %%i in (%compFile%) do (
  52.         echo.&echo :: Currently checking %%i&echo.
  53.         net use %tempDrive% \\%%i\%share% %anyParameter%>>nul 2>>%error%
  54.         if !errorlevel! NEQ 0 (
  55.                 echo "%%i","Error">>"%output%"
  56.                 echo :: There was an error accessing "%%i" >>%error%
  57.                 echo.>>%error%
  58.         ) else (
  59.                 pushd %tempDrive%>nul 2>&1
  60.                 @if exist %file1% (
  61.                         @if exist %file2% (
  62.                                 echo "%%i","Yes">>"%output%"
  63.                         ) else (
  64.                                 echo "%%i","No">>"%output%"
  65.                         )
  66.                 ) else (
  67.                         echo "%%i","No">>"%output%"
  68.                 )
  69.         )
  70.         popd
  71.         net use %tempDrive% /del /y>>nul 2>>&1
  72. )