Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for renewusb.bat

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

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. IF     "%OS%"=="Windows_NT" SETLOCAL
  5. VER | FIND "Windows NT" >NUL && GOTO Syntax
  6.  
  7. :: Check command line arguments -- none required
  8. IF NOT "%~1"=="" GOTO Syntax
  9.  
  10. :: Check if DEVCON.EXE is available and if not, prompt for download
  11. SET DevconAvailable=
  12. SET Download=
  13. DEVCON.EXE /? >NUL 2>&1
  14. IF ERRORLEVEL 1 (
  15. 	SET DevconAvailable=No
  16. 	ECHO This batch file requires Microsoft's DEVCON untility.
  17. 	SET /P Download=Do you want to download it now? [y/N] 
  18. )
  19.  
  20. :: Start download if requested
  21. IF /I "%Download%"=="Y" (
  22. 	START "WDK" https://www.microsoft.com/en-us/download/details.aspx?id=11800
  23. 	ECHO.
  24. 	ECHO Install the downloaded WDK, or read
  25. 	ECHO http://www.robvanderwoude.com/devcon.php
  26. 	ECHO to find out how to install DEVCON.EXE only.
  27. 	ECHO Make sure DEVCON.EXE is in the PATH, then try again.
  28. )
  29.  
  30. :: Abort if DEVCON.EXE is not available yet
  31. IF "%DevconAvailable%"=="No" GOTO End
  32.  
  33. :: List and remove all USB devices
  34. >> RenewUSB.dat ECHO.%Date%, %Time%
  35. DEVCON FindAll =USB | FIND ":" >> RenewUSB.dat
  36. FOR /F "tokens=1 delims=:	 " %%A IN ('DEVCON FindAll ^=USB ^| FIND ":"') DO DEVCON Remove "@%%A"
  37. DEVCON FindAll USB* | FIND ":" >> RenewUSB.dat
  38. FOR /F "tokens=1 delims=:	 " %%A IN ('DEVCON FindAll USB*  ^| FIND ":"') DO DEVCON Remove "@%%A"
  39.  
  40. :: Rescan for new hardware
  41. DEVCON ReScan
  42.  
  43. :: Done
  44. ENDLOCAL
  45. GOTO End
  46.  
  47. :Syntax
  48. ECHO.
  49. ECHO RenewUSB.bat,  Version 1.01 for Windows 2000 / XP
  50. ECHO Use DEVCON to remove all USB devices and then scan for new devices
  51. ECHO.
  52. ECHO Usage:  RENEWUSB
  53. ECHO.
  54. ECHO Notes:  [1] This batch file requires Microsoft's DEVCON utility,
  55. ECHO             part of the Windows Driver Kit ^(WDK^), available at
  56. ECHO             https://www.microsoft.com/en-us/download/details.aspx?id=11800
  57. ECHO             You will be prompted for download if it isn't found.
  58. ECHO         [2] This batch file requires elevated privileges.
  59. ECHO         [3] I tested this batch file on my own PC running Windows 2000 Pro SP4.
  60. ECHO             However, I cannot guarantee flawless operation on any other PC.
  61. ECHO             Use this batch file entirely at your own risk. Make sure you have
  62. ECHO             a recent full backup available in case something might go wrong.
  63. ECHO         [4] Before removal each USB device is logged in RENEWUSB.DAT.
  64. ECHO.
  65. ECHO Written by Rob van der Woude
  66. ECHO http://www.robvanderwoude.com
  67.  
  68. :End
  69.  

page last uploaded: 2017-07-06, 12:37