1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Windows Whats wrong with my batch file?

Discussion in 'Tech Support' started by Nealieboyee, 30 Sep 2014.

  1. Nealieboyee

    Nealieboyee Packaging Master!

    Joined:
    14 Aug 2009
    Posts:
    3,826
    Likes Received:
    458
    Hi All,
    I'm trying to restart the print spooler with a batch file, and automatically answer the prompt to stop the tcp/ip service with a Y or yes.

    I have this:

    @echo off
    rem stop spooler
    net stop spooler
    rem delete print jobs
    rem start spooler
    net start spooler
    net start lpdsvc
    echo done!

    What am I missing?
     
  2. Sp!

    Sp! Minimodder

    Joined:
    6 Dec 2002
    Posts:
    1,543
    Likes Received:
    30
    Last edited: 30 Sep 2014
  3. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    Why do you want to stop the TCP/IP service?
     
  4. Nealieboyee

    Nealieboyee Packaging Master!

    Joined:
    14 Aug 2009
    Posts:
    3,826
    Likes Received:
    458
    The print spooler won't stop unless the TCP/IP service is stopped too, because the TCP/IP print server is dependent on the spooler.
     
  5. Nealieboyee

    Nealieboyee Packaging Master!

    Joined:
    14 Aug 2009
    Posts:
    3,826
    Likes Received:
    458
    DUH!

    I stopped the TCPIP service FIRST then stopped the spooler and it didn't prompt. It now works perfectly.

    Thanks all!
     
  6. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    Yeah thought it might be a dependency, so you want this then...

     
    Pookie likes this.
  7. Nealieboyee

    Nealieboyee Packaging Master!

    Joined:
    14 Aug 2009
    Posts:
    3,826
    Likes Received:
    458
    Thanks Atomic. Mine looked very similar but I've changed it to look like yours. Works like a charm!

    The main reason I'm doing this is because the printer drivers on our print server seem to have memory leaks, and I see the spooler memory size go up to 1.5GB throughout the day, which eventually causes problems printing. Restarting the spooler service always works, so I just wanted to automate it with a batch file and task scheduler.
     
  8. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    Ouch that's a badly written driver.

    If it's running as a scheduled task you can remove the echo lines as you won't see the console output:

    Code:
    net stop lpdsvc
    net stop spooler 
    net start spooler 
    net start lpdsvc
    
    And if you want to clear jobs from the spooler also:

    Code:
    net stop lpdsvc
    net stop spooler 
    ping localhost -n 4 > nul
    del /q %SystemRoot%\system32\spool\printers\*.*
    net start spooler 
    net start lpdsvc
    
    The 'ping' line just adds a delay before clearing the spooler, you don't really need it but it helps to be sure all file locks are clear.
     
  9. Margo Baggins

    Margo Baggins I'm good at Soldering Super Moderator

    Joined:
    28 May 2010
    Posts:
    5,649
    Likes Received:
    268
    you can just put a /y after a net stop to automatically answer yes to it stopping other services.

    net stop spooler /y

    stops spooler AND fax service (if you use fax, relies on the print spooler)
     
  10. Nealieboyee

    Nealieboyee Packaging Master!

    Joined:
    14 Aug 2009
    Posts:
    3,826
    Likes Received:
    458
    Ah thanks Margo. I was putting the /y before the net stop command.

    I think I'll use the delete print queue command. It saves me having to clear it manually.
     

Share This Page