31 lines
1.1 KiB
Batchfile
31 lines
1.1 KiB
Batchfile
@echo off
|
|
|
|
:: Define variables
|
|
set OutputDir=D:\Applications\ClearPrinterSpooler
|
|
set TaskName=ClearPrinterSpoolerTask
|
|
set ScriptPath=%OutputDir%\ClearPrinterSpooler.bat
|
|
set ScheduleTime=04:00
|
|
set TaskFolder="\ImagePlus"
|
|
|
|
echo Creating directory %OutputDir%
|
|
if not exist %OutputDir% mkdir %OutputDir%
|
|
|
|
:: Create the batch script to clear printer spooler
|
|
echo @echo off > %ScriptPath%
|
|
echo echo Stopping Print Spooler... >> %ScriptPath%
|
|
echo net stop spooler >> %ScriptPath%
|
|
echo echo Deleting spooled print jobs... >> %ScriptPath%
|
|
echo del /Q /F C:\Windows\System32\spool\PRINTERS\*.* >> %ScriptPath%
|
|
echo echo Starting Print Spooler... >> %ScriptPath%
|
|
echo net start spooler >> %ScriptPath%
|
|
echo echo Printer spooler cleared successfully. >> %ScriptPath%
|
|
|
|
:: Check if the task exists and delete it if found
|
|
schtasks /Query /TN %TaskFolder%\%TaskName% > nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
schtasks /Delete /TN %TaskFolder%\%TaskName% /F
|
|
echo Existing task '%TaskName%' deleted.
|
|
)
|
|
|
|
:: Create the scheduled task
|
|
schtasks /Create /TN %TaskFolder%\%TaskName% /TR "%ScriptPath%" /SC DAILY /ST %ScheduleTime%
|