-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_spooler_restarter.bat
More file actions
56 lines (48 loc) · 1.63 KB
/
print_spooler_restarter.bat
File metadata and controls
56 lines (48 loc) · 1.63 KB
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
:: ============================================================================
:: PRINT SPOOLER RESTARTER SCRIPT (Enhanced Version)
:: ----------------------------------------------------------------------------
:: This script performs the following operations:
:: - Verifies that it's running with administrative privileges
:: - Stops the Print Spooler service
:: - Waits for 5 seconds before restarting the service
:: - Restarts the Print Spooler service
:: - Provides error feedback if any service command fails
:: ============================================================================
@echo off
:: --- Check for administrative rights ---
:: net session requires admin; if command fails, exit the script
net session >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo This script must be run as administrator.
pause
exit /b
)
:: --- Display header section ---
echo.
echo ----------------------------
echo PRINT SPOOLER RESTARTER TOOL
echo ----------------------------
echo.
:: --- Stop the Print Spooler service ---
echo Stopping print spooler...
net stop spooler
IF %ERRORLEVEL% NEQ 0 (
echo ERROR: Failed to stop Print Spooler.
goto End
)
:: --- Brief pause before restarting ---
echo Waiting 5 seconds before restarting...
timeout /t 5 /nobreak >nul
:: --- Start the Print Spooler service ---
echo Starting print spooler...
net start spooler
IF %ERRORLEVEL% NEQ 0 (
echo ERROR: Failed to start Print Spooler.
goto End
)
:: --- Success message ---
echo Print Spooler successfully restarted.
:End
:: --- Final prompt to keep script window open ---
echo.
set /P DUMMY=Press ENTER to continue...