-
Notifications
You must be signed in to change notification settings - Fork 1
/
printerControl.cs
78 lines (59 loc) · 2.08 KB
/
printerControl.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
using System.Management.Instrumentation;
/*
PrinterStatus by: @CheCheSwap {Custom Async table in Stmt32 Operating System capability}
Data type: uint16
Access type: Read-only
Qualifiers: MappingStrings ("MIB.IETF|Printer-MIB.hrPrinterStatus")
Status information for a printer that is different from information specified in the logical device Availability property.
This property is inherited from CIM_Printer.
Other (1)
Unknown (2)
Idle (3)
Printing (4)
Warmup (5)
Warming Up
Stopped Printing (6)
Offline (7)
*/
namespace MundoMusical.CONFIGURACION_DE_IMPRESION
{
public static class printerControl
{
public static bool printIsSafe(string name){
bool ready = false;
if (name == null || name == string.Empty)
{
return ready;
}
string query =$"SELECT * from Win32_Printer WHERE Name LIKE '%{name}%'";
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
using (ManagementObjectCollection resquery = searcher.Get())
{
try
{
foreach (ManagementObject printer in resquery)
{
if (!printer["WorkOffline"].ToString().ToUpper().Equals("TRUE"))
{
if (printer.Properties["PrinterStatus"].Value.ToString() == "3")
{
ready = true;
}
}
}
}
catch (ManagementException ex)
{
genericDefinitions.error(ex.ToString());
}
}
return ready;
}
}
}