-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_Printers.ahk
140 lines (130 loc) · 7.15 KB
/
class_Printers.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62955&sid=946210846b62fc770d1a8241764148d4
Class Printers
{
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/addprinterconnection
; ===========================================================================================================================
AddConnection(printer)
{
if !(DllCall("winspool.drv\AddPrinterConnection", "str", printer))
return false
return true
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/closeprinter
; ===========================================================================================================================
CloseHandle(handle)
{
if !(DllCall("winspool.drv\ClosePrinter", "str", handle))
return false
return true
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/deleteprinterconnection
; ===========================================================================================================================
DeleteConnection(printer)
{
if !(DllCall("winspool.drv\DeletePrinterConnection", "str", printer))
return false
return true
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/enumprinters
; ===========================================================================================================================
Enum(flags)
{
if !(DllCall("winspool.drv\EnumPrinters", "uint", flags, "ptr", 0, "uint", 2, "ptr", 0, "uint", 0, "uint*", size, "uint*", 0))
{
size := VarSetCapacity(buf, size << 1, 0)
if (DllCall("winspool.drv\EnumPrinters", "uint", flags, "ptr", 0, "uint", 2, "ptr", &buf, "uint", size, "uint*", 0, "uint*", count))
{
addr := &buf, PRINTER_INFO_2 := []
loop % count
{
PRINTER_INFO_2[A_Index, "ServerName"] := StrGet(NumGet(addr + 0, "ptr"))
PRINTER_INFO_2[A_Index, "PrinterName"] := StrGet(NumGet(addr + A_PtrSize, "ptr"))
PRINTER_INFO_2[A_Index, "ShareName"] := StrGet(NumGet(addr + A_PtrSize * 2, "ptr"))
PRINTER_INFO_2[A_Index, "PortName"] := StrGet(NumGet(addr + A_PtrSize * 3, "ptr"))
PRINTER_INFO_2[A_Index, "DriverName"] := StrGet(NumGet(addr + A_PtrSize * 4, "ptr"))
PRINTER_INFO_2[A_Index, "Comment"] := StrGet(NumGet(addr + A_PtrSize * 5, "ptr"))
PRINTER_INFO_2[A_Index, "Location"] := StrGet(NumGet(addr + A_PtrSize * 6, "ptr"))
;DevMode := NumGet(addr + A_PtrSize * 7, "ptr")
; https://docs.microsoft.com/en-us/windows/desktop/api/Wingdi/ns-wingdi-_devicemodea
PRINTER_INFO_2[A_Index, "SepFile"] := StrGet(NumGet(addr + A_PtrSize * 8, "ptr"))
PRINTER_INFO_2[A_Index, "PrintProcessor"] := StrGet(NumGet(addr + A_PtrSize * 9, "ptr"))
PRINTER_INFO_2[A_Index, "Datatpye"] := StrGet(NumGet(addr + A_PtrSize * 10, "ptr"))
PRINTER_INFO_2[A_Index, "Parameters"] := StrGet(NumGet(addr + A_PtrSize * 11, "ptr"))
;SecurityDescriptor := NumGet(addr + A_PtrSize * 12, "ptr")
; https://docs.microsoft.com/de-de/windows/desktop/api/winnt/ns-winnt-_security_descriptor
PRINTER_INFO_2[A_Index, "Attributes"] := NumGet(addr + A_PtrSize * 13, "uint")
PRINTER_INFO_2[A_Index, "Priority"] := NumGet(addr + A_PtrSize * 13 + 4, "uint")
PRINTER_INFO_2[A_Index, "DefaultPriority"] := NumGet(addr + A_PtrSize * 13 + 8, "uint")
PRINTER_INFO_2[A_Index, "StartTime"] := NumGet(addr + A_PtrSize * 13 + 12, "uint")
PRINTER_INFO_2[A_Index, "UntilTime"] := NumGet(addr + A_PtrSize * 13 + 16, "uint")
PRINTER_INFO_2[A_Index, "Status"] := NumGet(addr + A_PtrSize * 13 + 20, "uint")
PRINTER_INFO_2[A_Index, "Jobs"] := NumGet(addr + A_PtrSize * 13 + 24, "uint")
PRINTER_INFO_2[A_Index, "AveragePPM"] := NumGet(addr + A_PtrSize * 13 + 28, "uint")
addr += A_PtrSize * 13 + 32
}
return PRINTER_INFO_2
}
}
return false
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/getdefaultprinter
; ===========================================================================================================================
GetDefault()
{
if !(DllCall("winspool.drv\GetDefaultPrinter", "ptr", 0, "uint*", size))
{
size := VarSetCapacity(buf, size << 1, 0)
if !(DllCall("winspool.drv\GetDefaultPrinter", "str", buf, "uint*", size))
return false
}
return buf
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/getprinter
; ===========================================================================================================================
GetInfo(printer)
{
if (handle := this.OpenHandle(printer))
{
if !(DllCall("winspool.drv\GetPrinter", "ptr", handle, "uint", 1, "ptr", 0, "uint", 0, "uint*", size))
{
size := VarSetCapacity(buf, size << 1, 0)
if (DllCall("winspool.drv\GetPrinter", "ptr", handle, "uint", 1, "ptr", &buf, "uint", size, "uint*", 0))
{
PRINTER_INFO_1 := {}
PRINTER_INFO_1.Flags := NumGet(&buf + 0, "uint")
PRINTER_INFO_1.Description := StrGet(NumGet(&buf + (A_PtrSize * 1), "uptr"), "utf-16")
PRINTER_INFO_1.Name := StrGet(NumGet(&buf + (A_PtrSize * 2), "uptr"), "utf-16")
PRINTER_INFO_1.Comment := StrGet(NumGet(&buf + (A_PtrSize * 3), "uptr"), "utf-16")
this.CloseHandle(handle)
return PRINTER_INFO_1
}
}
this.CloseHandle(handle)
}
return false
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/openprinter
; ===========================================================================================================================
OpenHandle(printer)
{
if !(DllCall("winspool.drv\OpenPrinter", "ptr", &printer, "ptr*", handle, "ptr", 0))
return false
return handle
}
; ===========================================================================================================================
; https://docs.microsoft.com/en-us/windows/desktop/printdocs/setdefaultprinter
; ===========================================================================================================================
SetDefault(printer)
{
if !(DllCall("winspool.drv\SetDefaultPrinter", "str", printer))
return false
return true
}
}