-
Notifications
You must be signed in to change notification settings - Fork 79
/
remove_all_printers_and_unused_drivers_and_ports.bat
80 lines (63 loc) · 2.49 KB
/
remove_all_printers_and_unused_drivers_and_ports.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
:: WARNING!!! This script will remove EVERY installed printer, their ports, and the unused drivers.
:: Use with caution.
:: You have been warned.
:: Source: http://www.reddit.com/r/usefulscripts/comments/1c0698/batch_remove_all_printers_unused_drivers_and/
cd %SystemDrive%\Windows\System32
setLocal EnableDelayedExpansion
CLS
:: Stop the spooler service
net stop spooler
:: Determine OS
If exist "%SystemDrive%\Users\Default\NTUSER.DAT" goto Win7
If exist "%SystemDrive%\Documents and Settings\All Users\NTUSER.DAT" goto WinXP
:WinXP
cls
Echo Removing all printers
:: Printer deletion
CSCRIPT /nologo %windir%\System32\prnmngr.vbs -x
:: Delete TCP/IP port
if exist %TEMP%\IPPorts.txt del %TEMP%\IPPorts.txt
if exist %TEMP%\IPPorts2.txt del %TEMP%\IPPorts2.txt
if exist %TEMP%\IPPorts3.txt del %TEMP%\IPPorts3.txt
cls
CSCRIPT /nologo %windir%\System32\prnport.vbs -l > %TEMP%\IPPorts.txt
type %TEMP%\IPPorts.txt | findstr IP_ > %TEMP%\IPPorts2.txt
for /f "tokens=* delims=" %%c in ('type %TEMP%\IPPorts2.txt') do (
set LINE=%%c
>> %TEMP%\IPPorts3.txt echo !LINE:~10!
)
for /f "delims=" %%x in (%TEMP%\IPPorts3.txt) do CSCRIPT /nologo %windir%\System32\prnport.vbs -d -r %%x
del %TEMP%\IPPorts.txt
del %TEMP%\IPPorts2.txt
del %TEMP%\IPPorts3.txt
:: Delete all un-used printer drivers
CSCRIPT /nologo %windir%\System32\prndrvr.vbs -x
goto Exit
:Win7
cls
Echo Removing all printers
:: Printer deletion
CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x
:: Delete TCP/IP port
if exist %TEMP%\IPPorts.txt del %TEMP%\IPPorts.txt
if exist %TEMP%\IPPorts2.txt del %TEMP%\IPPorts2.txt
if exist %TEMP%\IPPorts3.txt del %TEMP%\IPPorts3.txt
if exist %TEMP%\IPPorts4.txt del %TEMP%\IPPorts4.txt
cls
CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -l > %TEMP%\IPPorts.txt
type %TEMP%\IPPorts.txt | findstr 172.20 > %TEMP%\IPPorts2.txt
type %TEMP%\IPPorts2.txt | findstr Port > %TEMP%\IPPorts3.txt
for /f "tokens=* delims=" %%c in ('type %TEMP%\IPPorts3.txt') do (
set LINE=%%c
>> %TEMP%\IPPorts4.txt echo !LINE:~10!
)
for /f "delims=" %%x in (%TEMP%\IPPorts4.txt) do CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r %%x
del %TEMP%\IPPorts.txt
del %TEMP%\IPPorts2.txt
del %TEMP%\IPPorts3.txt
del %TEMP%\IPPorts4.txt
:: Delete all used printer drivers
CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -x
goto Exit
:Exit
net start spooler