-
Notifications
You must be signed in to change notification settings - Fork 79
/
map_printers.bat
106 lines (87 loc) · 4.25 KB
/
map_printers.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
:: Purpose: Maps printers when a user logs in
:: Requirements: Specify the target print server and printer names below
:: Author: vocatus.gate@gmail.com // github.com/bmrf // reddit.com/user/vocatus // PGP: 0x07d1490f82a211a2
:: Usage: Place this script in %ProgramData%\Microsoft\Windows\Start Menu\Startup
:: History: 1.0.0 + Initial write
:::::::::::::::
:: VARIABLES :: ---- Set these to your desired values
:::::::::::::::
:: Rules for variables:
:: * NO quotes! (bad: "c:\directory\path" )
:: * NO trailing slashes on the path! (bad: c:\directory\ )
:: * Spaces are okay (okay: c:\my folder\with spaces )
:: * Network paths are okay (okay: \\server\share name )
:: ( \\172.16.1.5\share name )
:: Log settings
set LOGPATH=%TEMP%
set LOGFILE=map_printers.log
:: Printers to map
set PRINT_SERVER=\\blisw6syaaps004
set PRINTER1=DPTMS Bldg 1011 Basement iCafe RICOH MP C4504
set PRINTER2=DPTMS Bldg 1011 Basement iCafe 2 RICOH MP C4504
set PRINTER3=DPTMS Bldg 1011 Rm iCafe 3c RICOH MP C4504
:::::::::::::::::::::
:: PREP AND CHECKS ::
:::::::::::::::::::::
@echo off && cls
set SCRIPT_VERSION=1.0.0
set SCRIPT_UPDATED=2019-11-14
:: Get the date into ISO 8601 standard format (yyyy-mm-dd) so we can use it
FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
:::::::::::::
:: EXECUTE ::
:::::::::::::
:: Map the printers
echo.
echo %CUR_DATE% %TIME% Mapping printers...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% Mapping printers, please don't close this window...
echo.
:: Printer 1
echo %CUR_DATE% %TIME% Checking %PRINTER1% online status...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% Checking %PRINTER1% online status...
rundll32 printui.dll,PrintUIEntry /q /Xg /f "%TEMP%\printer_check" /n"%PRINT_SERVER%\%PRINTER1%" >nul
if /i not exist "%TEMP%\printer_check" (
echo %CUR_DATE% %TIME% "%PRINTER1%" appears to be down, skipping.>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER1%" appears to be down, skipping.
) else (
echo %CUR_DATE% %TIME% "%PRINTER1%" online, mapping now...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER1%" online, mapping now...
rundll32 printui.dll,PrintUIEntry /q /in /n"%PRINT_SERVER%\%PRINTER1%"
echo %CUR_DATE% %TIME% Mapped.
)
if exist "%TEMP%\printer_check" del /f /q "%TEMP%\printer_check" >nul
:: Printer 2
echo %CUR_DATE% %TIME% Checking %PRINTER2% online status...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% Checking %PRINTER2% online status...
rundll32 printui.dll,PrintUIEntry /q /Xg /f "%TEMP%\printer_check" /n"%PRINT_SERVER%\%PRINTER2%" >nul
if /i not exist "%TEMP%\printer_check" (
echo %CUR_DATE% %TIME% "%PRINTER2%" appears to be down, skipping.>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER2%" appears to be down, skipping.
) else (
echo %CUR_DATE% %TIME% "%PRINTER2%" online, mapping now...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER2%" online, mapping now...
rundll32 printui.dll,PrintUIEntry /q /in /n"%PRINT_SERVER%\%PRINTER2%"
echo %CUR_DATE% %TIME% Mapped.
)
if exist "%TEMP%\printer_check" del /f /q "%TEMP%\printer_check" >nul
:: Printer 3
echo %CUR_DATE% %TIME% Checking "%PRINTER3%"...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% Checking "%PRINTER3%"...
rundll32 printui.dll,PrintUIEntry /q /Xg /f "%TEMP%\printer_check" /n"%PRINT_SERVER%\%PRINTER3%" >nul
if /i not exist "%TEMP%\printer_check" (
echo %CUR_DATE% %TIME% "%PRINTER3%" appears to be down, skipping.>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER3%" appears to be down, skipping.
) else (
echo %CUR_DATE% %TIME% "%PRINTER3%" online, mapping now...>> "%LOGPATH%\%LOGFILE%"
echo %CUR_DATE% %TIME% "%PRINTER3%" online, mapping now...
rundll32 printui.dll,PrintUIEntry /q /in /n"%PRINT_SERVER%\%PRINTER3%"
echo %CUR_DATE% %TIME% Mapped.
)
if exist "%TEMP%\printer_check" del /f /q "%TEMP%\printer_check" >nul
:: Wrap-Up
echo %CUR_DATE% %TIME% Printers mapped.>> "%LOGPATH%\%LOGFILE%"
echo Printers mapped, have a nice day!
echo Please contact the S-6 if you have any questions.
echo This window will close in 3 seconds.
ping -n 5 localhost >nul