Advertisement
Calvus

Remove all printers, unused drivers, and left behind ports

Apr 9th, 2013
1,953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :: WARNING!!! This script will remove EVERY installed printer, their ports, and the unused drivers.
  2. :: Use with caution.
  3. :: You have been warned.
  4.  
  5. Cd \
  6. Cd Windows\System32
  7. setLocal EnableDelayedExpansion
  8. CLS
  9.  
  10. :: Determine OS
  11. If exist "c:\Users\Default\NTUSER.DAT" goto Win7
  12. If exist "c:\Documents and Settings\All Users\NTUSER.DAT" goto WinXP
  13.  
  14. :WinXP
  15. cls
  16. Echo Removing all printers
  17. :: Printer deletion
  18. CSCRIPT /nologo %windir%\System32\prnmngr.vbs -x
  19.  
  20. :: Delete TCP/IP port
  21. if exist c:\IPPorts.txt del c:\IPPorts.txt
  22. if exist c:\IPPorts2.txt del c:\IPPorts2.txt
  23. if exist c:\IPPorts3.txt del c:\IPPorts3.txt
  24. cls
  25.  
  26. CSCRIPT /nologo %windir%\System32\prnport.vbs -l > c:\IPPorts.txt
  27. type c:\IPPorts.txt | findstr IP_ > c:\IPPorts2.txt
  28. for /f "tokens=* delims=" %%c in ('type c:\IPPorts2.txt') do (
  29.  set LINE=%%c
  30.  >> c:\IPPorts3.txt echo !LINE:~10!
  31. )
  32. for /f "delims=" %%x in (c:\IPPorts3.txt) do CSCRIPT /nologo %windir%\System32\prnport.vbs -d -r %%x
  33.  
  34. del c:\IPPorts.txt
  35. del c:\IPPorts2.txt
  36. del c:\IPPorts3.txt
  37.  
  38. :: Delete all un-used printer drivers
  39. CSCRIPT /nologo %windir%\System32\prndrvr.vbs -x
  40.  
  41. goto Exit
  42.  
  43. :Win7
  44. cls
  45. Echo Removing all printers
  46. :: Printer deletion
  47. CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x
  48.  
  49. :: Delete TCP/IP port
  50. if exist c:\IPPorts.txt del c:\IPPorts.txt
  51. if exist c:\IPPorts2.txt del c:\IPPorts2.txt
  52. if exist c:\IPPorts3.txt del c:\IPPorts3.txt
  53. if exist c:\IPPorts4.txt del c:\IPPorts4.txt
  54. cls
  55.  
  56. CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -l > c:\IPPorts.txt
  57. type c:\IPPorts.txt | findstr 172.20 > c:\IPPorts2.txt
  58. type c:\IPPorts2.txt | findstr Port > c:\IPPorts3.txt
  59. for /f "tokens=* delims=" %%c in ('type c:\IPPorts3.txt') do (
  60.  set LINE=%%c
  61.  >> c:\IPPorts4.txt echo !LINE:~10!
  62. )
  63. for /f "delims=" %%x in (c:\IPPorts4.txt) do CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r %%x
  64.  
  65. del c:\IPPorts.txt
  66. del c:\IPPorts2.txt
  67. del c:\IPPorts3.txt
  68. del c:\IPPorts4.txt
  69.  
  70. :: Delete all used printer drivers
  71. CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -x
  72.  
  73. goto Exit
  74.  
  75. :Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement