• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Batch file

Sandeep Bhugoo

New Member
Joined
Jun 19, 2014
Messages
6 (0.00/day)
hello,

i am not so good in creating batch files i need some help in creating one.

in the following path

C:\Windows\System32\spool\PRINTERS

there is a .SHD and .SPL file created when prints launched

i need a batch file to open the .SPL in notepad first then on closing the notepad opened, all the files .SHD and .SPL are permanently deleted

any help please

code to open the notepad is as below

start notepad "C:\windows\system32\spool\printers\FP00002.SPL"

the file is opened but there are unwanted characters that appear as well as below

upload_2014-6-19_10-43-2.png
 
in fact when i reset a user password it is supposed to print the generated password to a printer but i don't want to print it. i want the batch file to open the .spl file generated in notepad, i note the password then on closing the notepad, the files .shd and .spl are deleted permanently from the folder
 
if you need to clear spooler cache try this:


Code:
@Echo OFF
CLS
net stop spooler
del c:\system32\spool\printers\*.shd
del c:\system32\spool\printers\*.spl
net start spooler

much nicer using %windir% variable:

Code:
net stop spooler
del %windir%\system32\spool\printers\*.shd
del %windir%\system32\spool\printers\*.spl
net start spooler

i don´t think you can read it as plain text
also here is an emf/spl viewer
http://www.fengyuan.com/download.html (emf.zip)
 
Last edited:
thank you for your reply. how to merge the codes so that the batch file does this

the batch file displays the options below

1. open the *.spl file in notepad
2. delete the *.shd and *.spl files
3.exit

commands execute as options are selected
 
does it needs to open a single file ? or multiple in spooler dir

note: it changes file name randomly i think
 
it has to open any .spl file present. each time the folder will be cleared when choosing the second option to clear. when another generation is done, another .spl file is created. i run the batch file to open it again when choosing option 1. ya the file name changes each time...
 
try some like this (untested)

batch file:

Code:
@EchoOFF
CLS
:MENU
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF
:SPL
for %%X in ("%windir%\system32\spool\printers\"*.spl) do notepad %%X
GOTO MENU
:CLEAR
net stop spooler
del %windir%\system32\spool\printers\*.shd
del %windir%\system32\spool\printers\*.spl
net start spooler
GOTO MENU



save as *.bat


fixed :MENU tag
 
Last edited:
recopy script added the :menu tag and it should jump back to menu

might also be run as admin to have permission of deleting files in spooler dir
 
Code:
@ECHO OFF
CLS
:MENU
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF
:SPL
if exist {"%windir%\system32\spool\printers\"*.spl} (
        ECHO .
        ECHO Files found, opening...
        ECHO.
        for %%X in ("%windir%\system32\spool\printers\"*.spl) do notepad %%X
        GOTO MENU
    ) else (
        ECHO.
        ECHO No Files found...
        ECHO.
        GOTO MENU
    )
:CLEAR
if exist {"%windir%\system32\spool\printers\"*.spl} (
        ECHO .
        ECHO Files found, deleting...
        ECHO.
        net stop spooler
        del %windir%\system32\spool\printers\*.shd
        del %windir%\system32\spool\printers\*.spl
        net start spooler
        GOTO MENU
    ) else (
        ECHO.
        ECHO No Files found...
        ECHO.
        GOTO MENU
    )
:EOF
exit


a bit nicer, added some file checks and notes
 
dont need to cls the @Echo off and its advisable to @Echo on at the end of a batch file just before it exits.. "but next to no one does it"

i assume your doing cls so a new menu will be clean though, which keeps the bat nicer looking. rather than having a cls at the end of every option.
I think your way looks a lot cleaner than i would have done.. and i d have probably ended up with something looking a lot more like this.
Im prety sure your way is probably the better way the more i think about it. but id have still done it the way im adding just to ensure that it always ended at the menu.
I dont see any reason why your way wouldnt jump back to the menu though. so your way has to be better.

Code:
@ECHO OFF
:MENU
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF
:SPL
if exist {"%windir%\system32\spool\printers\"*.spl} (
ECHO .
ECHO Files found, opening...
ECHO.
for %%X in ("%windir%\system32\spool\printers\"*.spl) do notepad %%X
pause
cls
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF
) else (
ECHO.
ECHO No Files found...
pause
cls
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF
)
:CLEAR
if exist {"%windir%\system32\spool\printers\"*.spl} (
ECHO .
ECHO Files found, deleting...
ECHO.
net stop spooler
del %windir%\system32\spool\printers\*.shd
del %windir%\system32\spool\printers\*.spl
net start spooler
ECHO deleted
pause
cls
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF

) else (
ECHO.
ECHO No Files found...
pause
cls
ECHO ...............................................
ECHO.
ECHO 1 - Open *.spl Files
ECHO 2 - Clear Spooler cache
ECHO 3 - EXIT
ECHO.
ECHO ...............................................
ECHO.

SET /P M=Type 1, 2, or 3 then press ENTER:
IF %M%==1 GOTO SPL
IF %M%==2 GOTO CLEAR
IF %M%==3 GOTO EOF

)
:EOF
cls
pause
@Echo on
 
Last edited:
this is more shorter, the other where to reach the goal

Code:
@ECHO OFF
REM Set File Path variable
SET SPLFILES=%WINDIR%\SYSTEM32\spool\printers\
REM Build Menu
:MENU
    CLS
    ECHO ...............................................
    ECHO.
    ECHO 1 - Open *.spl Files
    ECHO 2 - Clear Spooler cache
    ECHO 3 - EXIT
    ECHO.
    ECHO ...............................................
    ECHO.
    SET /P M=Type 1, 2, or 3 then press ENTER:
    IF %M%==1 GOTO SPL
    IF %M%==2 GOTO CLEAR
    IF %M%==3 GOTO EOF
REM check if there are any and open files with notepad
:SPL
    REM "FORFILES" Native command in Vista/Windows7/2008, via Resource Kit for XP
    for %%G in (.spl) do FORFILES -p %SPLFILES% -m  *%%G -c "cmd /c ECHO Opening File: @path & cmd /c notepad @path"
    ECHO.
    pause
    goto MENU
REM check if there are any stop spooler , delete files, start spooler
:CLEAR
    net stop spooler
    ECHO.
    REM "FORFILES" Native command in Vista/Windows7/2008, via Resource Kit for XP
    for %%G in (.shd, .spl) do FORFILES -p %SPLFILES% -m  *%%G -c "cmd /c ECHO Deleting File: @path & cmd /c del @path /Q"
    ECHO.
    net start spooler
    pause
    goto MENU
REM Exit Script
:EOF
    exit

have fun
 
Last edited:
did you try without %s? Just system32?

nope not working,
you could do some like this to set Env Variable

setx -m System32"%windir%\System32\"

for current User

but its similar to my:

SET SPLFILES=%WINDIR%\SYSTEM32\spool\printers\


type: set in commad-line to see your system env variables
 
Last edited:
Back
Top