Results 1 to 3 of 3
  1. #1
    Administrator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    3,542
    Thanks
    154
    Thanked 978 Times in 779 Posts

    AutoHotkey - Clearing Windows' print queue

    Long story short... my sister's printer kept hanging but (using TeamViewer) I found it could be kicked back into operation by clearing the print queue.

    I adapted a post in the AutoHotkey forums to keep her going until I can hopefully come up with a more permanent solution:

    Code:
    ; Based on https://autohotkey.com/boards/viewtopic.php?f=6&t=24987&hilit=print+queue
    #SingleInstance force ; Ensure only one instance at a time
    #NoTrayIcon ; Suppress the default icon in the Notification Area
    
    ; Prompt to 'Run as Admin', i.e. show UAC dialog
    If Not A_IsAdmin
    {
       Run *RunAs "%A_ScriptFullPath%"  ; Requires AHK v1.0.92.01+
       ExitApp
    }
    
    ; Show user message to inform what's happening
    SplashImage,, W300 H120,, `nPlease wait...`n`nThe Printer queue is being cleared.`n`n This may take up to 10 seconds., Clear Printer Queue
    
    ; Stop the Print Spooler
    Runwait, %comspec% /c "net stop spooler",, hide
    
    ; Windows has its Print Queue located at the path used below.
    Runwait, %comspec% /c "del C:\Windows\System32\spool\printers\* /Q /F /S",, hide ;  Delete all files in the Print Queue (using [Q]uiet mode, [F]orce and clear [S]ub-folders switches)
    ; See https://ss64.com/nt/del.html for more info about the DEL command
    
    ; Restart the Print Spooler
    Runwait, %comspec% /c "net start spooler",, hide
    
    ; Close the information message
    splashimage, off
    
    ExitApp
    All it does is pop the following dialog, stop and restart the spooler service in elevated mode (i.e. as Administrator) then close the dialog:
    printer_queue_being_cleared.png

    Hope this helps...

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,018
    Thanks
    429
    Thanked 1,611 Times in 1,460 Posts
    Rick,

    Here's a PowerShell version that has a Setup switch which will add a scheduled task to run as Admin and a desktop shortcut (which can be moved if you wish) to call it.

    It also includes comment based help file.

    Just place the script (program) in the directory where you want to run it from and then run the program from an elevated PS session with the -Setup argument.

    Clear-PrintSpooler.zip: Clear-PrintSpooler.zip

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Administrator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    3,542
    Thanks
    154
    Thanked 978 Times in 779 Posts
    Quote Originally Posted by RetiredGeek
    Here's a PowerShell version that has a Setup switch which will add a scheduled task to run as Admin and a desktop shortcut (which can be moved if you wish) to call it.
    That's really cool... thank you!

    I'll have to look into creating scheduled tasks from within AHK.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •