I use the same commands but wrapped in an AutoHotkey script which takes care of the elevation and provides an onscreen message:
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 ; Surpress the default Notification tray icon
; 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
}
SplashImage,, W300 H120,, `nPlease wait...`n`nThe Printer queue is being cleared.`n`n This may take up to 10 seconds., Clear Printer Queue ; Show user message to inform what's happening
Runwait, %comspec% /c "net stop spooler",, hide ; Stop the Print Spooler
; 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)
Runwait, %comspec% /c "net start spooler",, hide ; Restart the Print Spooler
splashimage, off ; Close the information message
ExitApp
I've added this as a right-click option using a REG file:
Code:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Clear Print Queue]
"Icon"="C:\\Windows\\System32\\shell32.dll,222"
"MUIVerb"="Clear Print Queue"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Clear Print Queue\command]
@="explorer /root,\"C:\\Support\\ClearPrinterQueue.ahk\""
Hope this helps...
_______________________________________________________________
EDIT: Despite this being a very old post (6 years!), someone left me the following visitor message 2 weeks ago asking me about my post (Hint: Don't send me visitor messages. I don't usually notice them):
very interested in this but trying hard to understand the instructions.
I've downloaded & installed AutoHotkey and that's not making much sense either.
As far as I can see, you've not assigned clearance of the print spooler to a key (i.e. made a hotkey).
As I understand it, the script is written in notepad and then saved with a .ahk file extension for importing into AutoHotkey - what then?
Also, struggling to understand where your additional command appears.
When I go to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell there is no Clear key - do I therefore create a registry key called 'Clear Print Queue' and if so, how? I right click on 'Shell' then 'New' and select Key what do I do next? Similarly for the second registry key.
I'd like to understand how these commands work.
All good questions so I'm going to answer them briefly one-by-one then do a step-by-step 'how to' then a 'how it works'.
I've downloaded & installed AutoHotkey and that's not making much sense either.
The AutoHotkey.exe executable is the script interpreter for AHK scripts. Once installed, AutoHotkey assigns itself a file association with text files ending with a .AHK file extension. Just install AutoHotkey then forget about it. Note: Although AutoHotkey is now at version 2, I'm still using version 1.1 (version 1.1.37.01 to be exact). I have no idea whether my .AHK script works with version 2 nor am I going to test it (because I haven't had a printer for the last 2 years).
As far as I can see, you've not assigned clearance of the print spooler to a key (i.e. made a hotkey).
Correct. Instead I call the .AHK script from the Windows desktop using Explorer's right-click context menu.
As I understand it, the script is written in notepad and then saved with a .ahk file extension for importing into AutoHotkey - what then?
Almost correct. You can use Notepad... but it's not very helpful. You'll find using a dedicated AHK script editor much easier to use. I use SciTE4AutoHotkey. It's a small, free IDE that lets you write, test/run, debug .AHK scripts. Yes, you save the text file scripts with a .AHK file extension. You don't actually 'import' the script into AutoHotkey... just call the script somehow - like double-clicking on the script file - and, because of the file association, that will, in turn, call the script interpreter.
Also, struggling to understand where your additional command appears.
I could have just 'run' the .AHK script by double-clicking on it or creating a shortcut to it but I decided instead to use the Windows shell - Explorer.exe - by adding a command to Explorer's right-click context menu. This way I could just right-click on a blank area of the Windows desktop to run the .AHK script from a shell icon
When I go to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell there is no Clear key - do I therefore create a registry key called 'Clear Print Queue' and if so, how? I right click on 'Shell' then 'New' and select Key what do I do next? Similarly for the second registry key.
You could do, but it's easier just merging a .REG file. I'll add one to this post.
Basically there's 2 parts to this - the first is to create the .AHK script and the second is to create the right-click context menu entry. To make it easier I've attached a ZIP file called ClearPrinterQueue.zip containing both the .AHK script and a .REG file to create the menu entry.
Here's how to use.
1. Use File Explorer to create a folder in the root of C: called Support.
2. Download the .ZIP file to C:\Support, right-click on it and unblock it then unzip the contents - ClearPrinterQueue.ahk and ClearPrinterQueue.reg.
3. Double-click on the ClearPrinterQueue.reg file and merge it into the registry. This will create the right-click Explorer context menu entry giving it a standard shell icon and a description of 'Clear Print Queue'. If you get an error merging it then it means you don't have the necessary rights to write to the HKLM hive. In this case, use Search (next to the Start button) for Registry Editor, right-click on the 'found' result, choose Run as administrator then use File > Import... to import the .REG file.
That's it. The change should be dynamic but if you right-click on a blank area of the desktop and cannot see the new Clear Print Queue entry then restart your device.
Here's how it works once you've carried out steps 1-3 above.
a. You right-click on a blank area of the desktop and select the new Clear Print Queue entry.
b. The ClearPrinterQueue.ahk script stored in the C:\Support folder is called and runs using the AutoHotkey.exe command interpreter (because of the file association with .AHK files).
c. The command interpreter processes the script line-by-line, first popping up a UAC prompt so the script runs 'as administrator'.
d. A 'User Information' message appears to show what's happening.
e. The Windows CMD command processor is called 3 times (with the necessary 'admin' privileges) to first stop the print spooler service, then to clear the print queue then to re-start the print spooler service.
f. The 'User Information' message is closed and the script terminates.
https://www.tenforums.com/attachment...interqueue.zip
Hope this helps...