-
Notifications
You must be signed in to change notification settings - Fork 0
/
sethpduplex.cpp
78 lines (63 loc) · 1.74 KB
/
sethpduplex.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
//
// sethpduplex
//
// Call powershell to enable duplexing
// Option to show whether the duplexer is available on my hp printer
//
//
#include <windows.h>
#include <iostream>
#include <string>
#include <filesystem>
#include <cstdio>
using std::string, std::cout, std::endl;
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;
int main(int argc, char *argv[])
{
string program = path(argv[0]).stem().string();
if (argc == 2 && string(argv[1]) == "--version") {
string product, version;
getProductAndVersion( product, version );
cout << program << " V" << version << " " << buildDate << endl;
exit(0);
}
else if (argc == 2 && (string(argv[1]) == "--get" ||
string(argv[1]) == "--view")) {
LRESULT rc = 0;
vector<name_value> pairs;
pairs = dumpDriverFeatures( DriverKey, FeatureKeyword );
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;
}
}
exit(rc);
}
//
// Do the work to enable the feature
//
enableDuplex(PrinterName, PropertyName);
cout << "Duplexer enabled on '" << PrinterName << "'" << endl;
bool LaunchedByDoubleClick = (consoleListLength() == 1);
cout << "This was " << (LaunchedByDoubleClick? "" : "not ") <<
"launched by double click" << endl;
// If the console is going to disappear, keep it on screen for a short time
if (LaunchedByDoubleClick) {
Sleep(4000);
}
return 0;
}