-
Notifications
You must be signed in to change notification settings - Fork 0
/
gethpduplex.cpp
89 lines (76 loc) · 2 KB
/
gethpduplex.cpp
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
//
// gethpduplex
//
// Show whether the duplexer is available on my hp printer
//
// Option to call powershell to enable duplexing
//
// Copyright (c) 2022 Tim Braun <[email protected]>
//
#include <windows.h>
#include <shlobj.h>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <filesystem>
#include <cstdlib>
using std::string, std::endl, std::cout, std::cerr;
using std::filesystem::path;
using std::vector, std::pair;
#include "hpprinterkeys.h"
#include "printerutils.h"
#include "getversion.h"
#include "utils.h"
const string buildDate = BUILD_DATE;
bool verbose = false;
vector<name_value> dumpDriverFeatures( const string key );
bool enableDuplex();
int main(int argc, char *argv[])
{
int rc = 0;
string program = path(argv[0]).stem().string();
if (argc == 2 && string(argv[1]) == "--version") {
string product, version;
getProductAndVersion( product, version );
cout << product << " V" << version << " " << buildDate << endl;
exit(0);
}
if (program == "sethpduplex" ||
(argc == 2 && string(argv[1]) == "--set")) {
if (!IsUserAnAdmin()) {
cout << "This may not work - you're not in admin group" << endl;
}
enableDuplex( PrinterName, PropertyName );
}
else {
vector<name_value> pairs;
pairs = dumpDriverFeatures( DriverKey, FeatureKeyword );
if (verbose) {
cout << "From CurrentControlset:" << endl;
for (const auto &p : pairs) {
cout << ' ' << p.first << " = " << p.second << endl;
}
}
for (const auto &p : pairs) {
if (p.first == "DuplexUnit") {
if (p.second == "TRUE") {
cout << "Duplexer is enabled." << endl;
}
else {
cout << "Duplexer is not available." << endl;
rc = 1;
}
break;
}
}
#if 0
cout << endl << "From WOW6432Node:" << endl;
pairs = dumpDriverFeatures( DriverKey64 );
for (const auto &p : pairs) {
cout << ' ' << p.first << " = " << p.second << endl;
}
#endif
}
return rc;
}