Last version before adding context menu:
Spoiler
6-17-2023 updated with button to open Control Panel (see below posts).
6-18-2023 Esc now closes GUI, but keeps app in RAM.
6-18-2023 Added fourth button, for Print Queue. Opens print queue of selected item.
6-17-2023 updated with button to open Control Panel (see below posts).
6-18-2023 Esc now closes GUI, but keeps app in RAM.
6-18-2023 Added fourth button, for Print Queue. Opens print queue of selected item.
Code: Select all
#SingleInstance, Force
;===================
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=118596&p=526363#p526363
; For AHK v1
; A tool to allow user to check and/or change default printer.
!^+p::
menu, tray, icon, shell32.dll,107
guiColor =
fontColor =
; ===== Get default printer name. ======
RegRead, defaultPrinter, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Windows, Device
; ==== Get list of installed printers ======
printerlist =
loop,HKCU,Software\Microsoft\Windows NT\CurrentVersion\devices
printerlist = %printerlist%%A_loopRegName%`n
printerlist := SubStr(printerlist, 1, strlen(printerlist)-2)
; ==== Put names in GUI ====
Gui, df:Destroy
Gui, df:color, %guiColor%
Gui, df:font, s12 bold c%FontColor%
Gui, df:Add, Text,, Set A Default Printer ...
Gui, df:font, s11 normal
Loop, parse, printerlist, `n
If instr(defaultPrinter, A_LoopField)
Gui, df:Add, Radio, checked vRadio%a_index%, %a_loopfield%
Else
Gui, df:Add, Radio, vRadio%a_index%, %a_loopfield%
Gui, df:Add, Button, default gSet, Set Printer
Gui, df:Add, Button, x+10 gQue, Print Queue
Gui, df:Add, Button, x+10 gPanel, Control Panel
Gui, df:Add, Button, x+10 , Cancel
Gui, df:Show, , Default Printer Changer
Return
Set:
Gui, df:Submit
Loop, parse, printerlist, `n
If Radio%a_index% <> 0
newDefault = %a_loopfield%
; ==== Set new default printer =====
RunWait, C:\Windows\System32\RUNDLL32.exe PRINTUI.DLL`, PrintUIEntry /y /n "%newDefault%" ; sets the printer
Gui, df:Destroy
Return
Que:
Gui, df:Submit
Loop, parse, printerlist, `n
If Radio%a_index% <> 0
viewThis = %a_loopfield%
; ==== View print queue for selected =====
runwait, rundll32 printui.dll`, PrintUIEntry /o /n "%viewThis%" ;- display printer queue view -User Garry
;runwait,RUNDLL32 PRINTUI.DLL`,PrintUIEntry /f "%f1%" /Xg /n "%viewThis%" ;- show printers specification in file F1
;runwait,rundll32 printui.dll`,PrintUIEntry /? ;- Help
;runwait,rundll32 printui.dll`,PrintUIEntry /p /n "%viewThis%" ;- printer properties
Gui, df:Destroy
Return
Panel:
; run,shell:PrintersFolder ;- show printers and with rightclick change as default printer -User Garry
run, control printers ;- maybe rightclick for problem solution -User Garry
Gui, df:Destroy
printerlist =
Return
dfGuiEscape:
dfGuiClose:
dfButtonCancel:
Gui, df:Destroy
printerlist =
Return
/*
; Stuff from User: Garry
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=118596&p=526470#p526470
F1:=a_scriptdir . "\test.txt"
printerA:="SnagIt 2023"
;---------------
runwait,RUNDLL32 PRINTUI.DLL`,PrintUIEntry /f "%f1%" /Xg /n "%printerA%" ;- show printers specification in file F1
runwait,rundll32 printui.dll`,PrintUIEntry /? ;- Help
runwait,rundll32 printui.dll`,PrintUIEntry /o /n "%printerA%" ;- display printer queue view
runwait,rundll32 printui.dll`,PrintUIEntry /p /n "%printerA%" ;- printer properties
try,
run,%f1% ;- show printers specification
run,shell:PrintersFolder
run,control printers
return
*/
6-19-2023 Version with right-click-on-item context menu
Spoiler
This version adds a context menu. The Switches variable has items pasted from the help window (see "Help this message" menu item). I removed all the ones that looked dangerous to me (delete this, disconnect that). Other people can add items back to the list if desired. Some commands won't work though, because the switch looks for a file name. I left the "View Print Queue" button on the bottom of the GUI. It is redundant now, but I like the button, because I check my print queue often.
This version adds a context menu. The Switches variable has items pasted from the help window (see "Help this message" menu item). I removed all the ones that looked dangerous to me (delete this, disconnect that). Other people can add items back to the list if desired. Some commands won't work though, because the switch looks for a file name. I left the "View Print Queue" button on the bottom of the GUI. It is redundant now, but I like the button, because I check my print queue often.
Code: Select all
#SingleInstance, Force
;===================
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=118596&p=526363#p526363
; For AHK v1 ; By Kunkel321 with help from Garry.
; A tool to allow user to check and/or change default printer.
;!^+p::
menu, tray, icon, shell32.dll,107
guiColor =
fontColor =
Switches =
(
/e display printing preferences
/ge enum per machine printer connections
/k print test page to specified printer
/o display printer queue view
/p display printer properties
/s display server properties
/y set printer as the default
/Xg get printer settings
/? help this message
)
; ===== Get default printer name. ======
RegRead, defaultPrinter, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Windows, Device
; ==== Get list of installed printers ======
printerlist =
loop,HKCU,Software\Microsoft\Windows NT\CurrentVersion\devices
printerlist = %printerlist%%A_loopRegName%`n
printerlist := SubStr(printerlist, 1, strlen(printerlist)-2)
;StringSplit, printerlist, printerlist, `n ; Determines number of lines
; ==== Put names in GUI ====
Gui, df:Destroy
Gui, df:color, %guiColor%
Gui, df:font, s12 bold c%FontColor%
; ---- put switches in menu ----
Loop, parse, Switches, `n
Menu,df: Menu1, Add, %A_LoopField%, Label%A_Index%
Gui, df:Add, Text,, Set A Default Printer ...
Gui, df:font, s10 normal
Gui, df:Add, Text,y+-3, [Right-click printer name for more commands]
Gui, df:font, s11 normal
Loop, parse, printerlist, `n
If instr(defaultPrinter, A_LoopField)
Gui, df:Add, Radio, checked vRadio%a_index%, %a_loopfield%
Else
Gui, df:Add, Radio, vRadio%a_index%, %a_loopfield%
Gui, df:Add, Button, default gSet, Set Printer
Gui, df:Add, Button, x+10 gQue, Print Queue
Gui, df:Add, Button, x+10 gPanel, Control Panel
Gui, df:Add, Button, x+10 , Cancel
Gui, df:Show, , Default Printer Changer
Return
Label1:
Label2:
Label3:
Label4:
Label5:
Label6:
Label7:
Label8:
Label9:
Label10:
Label11:
Label12:
Label13:
Label14:
Label15:
Label16:
Label17:
Label18: ; If you have more than 18 'Switches' lines, above, add more labels.
MenuItem := StrReplace(A_ThisLabel, "Label", "")
StringSplit, Switches, Switches, `n
ThisSwitch := Switches%MenuItem%
StringSplit, ThisSwitch, ThisSwitch, " "
ThisSwitch := ThisSwitch1
return
dfGuiContextMenu:
If (A_GuiControl) {
menu,df: Menu1, Show
MouseGetPos,,,,Control1
Loop, parse, printerlist, `n
If (A_GuiControl = "Radio" A_Index) && (ThisSwitch <> "") {
runwait, rundll32 printui.dll`, PrintUIEntry "%ThisSwitch%" /n "%A_LoopField%" ; Not sure why the /n has to be there....
ThisSwitch =
}
}
return
Set:
Gui, df:Submit
Loop, parse, printerlist, `n
If Radio%a_index% <> 0
newDefault = %a_loopfield%
; ==== Set new default printer =====
RunWait, C:\Windows\System32\RUNDLL32.exe PRINTUI.DLL`, PrintUIEntry /y /n "%newDefault%" ; sets the printer
Gui, df:Destroy
Return
Que:
Gui, df:Submit
Loop, parse, printerlist, `n
If Radio%a_index% <> 0
viewThis = %a_loopfield%
; ==== View print queue for selected =====
runwait, rundll32 printui.dll`, PrintUIEntry /o /n "%viewThis%" ;- display printer queue view -User Garry
Gui, df:Destroy
Return
Panel:
; run,shell:PrintersFolder ;- show printers and with rightclick change as default printer -User Garry
run, control printers ;- maybe rightclick for problem solution -User Garry
Gui, df:Destroy
printerlist =
Return
dfGuiEscape:
dfGuiClose:
dfButtonCancel:
Gui, df:Destroy
printerlist =
Return
/*
; Stuff from User: Garry
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=118596&p=526470#p526470
F1:=a_scriptdir . "\test.txt"
printerA:="SnagIt 2023"
;---------------
runwait,RUNDLL32 PRINTUI.DLL`,PrintUIEntry /f "%f1%" /Xg /n "%printerA%" ;- show printers specification in file F1
runwait,rundll32 printui.dll`,PrintUIEntry /? ;- Help
runwait,rundll32 printui.dll`,PrintUIEntry /o /n "%printerA%" ;- display printer queue view
runwait,rundll32 printui.dll`,PrintUIEntry /p /n "%printerA%" ;- printer properties
try,
run,%f1% ;- show printers specification
run,shell:PrintersFolder
run,control printers
return
*/
/=====================
5-14-2024 Update: A version for AHKv2 is here:
viewtopic.php?f=83&p=571743#p571743