-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchksys.cpp
206 lines (182 loc) · 5.67 KB
/
chksys.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "chksys.h"
chksys::chksys()
{
//ctor
INITchksys();
}
chksys::~chksys()
{
//dtor
}
std::string chksys::genwin(void)
{
/** private Funktion: Generiert eine BAT Datei und führt diese aus, liest Windows Version als String **/
{
//Bat Datei erstellen
std::ofstream batch;
batch.open("ver.bat", std::ios::out);
if(!batch)
{
initerfolg = false;
return 0;
}
batch <<"ver --> ver.txt";
batch.close();
system("ver.bat");
initerfolg = true;
}
std::cout <<"Windows Version wird ausgelesen...\n";
std::fstream in("ver.txt", std::ios::in);
if (in.good())
{
std::string s;
while (getline(in,s,'\0'));
std::string versionstext = s;
std::cout << versionstext;
in.close();
return versionstext;
}
else
{
initerfolg = false;
return "0";
}
}
void chksys::readwin(void)
{
/** public Funktion: vergleicht String mit Versionsnummern, gibt Windows-Versionnummer als INT zurück **/
{
//Analysiere und Vergleiche Werte
readstring = genwin();
std::size_t found = readstring.find("6.1.");
if (found!=std::string::npos)
{
win = 7;
}
found = readstring.find("6.3.");
if (found!=std::string::npos)
{
win = 8;
}
found = readstring.find("6.2.");
if (found!=std::string::npos)
{
win = 8;
}
found = readstring.find("10.0.");
if (found!=std::string::npos)
{
win = 10;
}
// Zerlege Werte
readstring.erase(0, 28);
readstring.erase(readstring.end()-2, readstring.end());
if(win != 0)
{
std::cout << "\nSoweit ermittelt handelt es sich um Windows " << win;
std::vector<std::string> aktuelles = {aktwin7,aktwin8,aktwin10};
for( const auto &s : aktuelles )
{
std::string temp = s;
found = readstring.find(temp);
if (found!=std::string::npos)
{
aktver = true;
}
}
if(aktver == false&&win!=0)std::cout << "\nEs wurde eine veraltete Version festgestellt!"<< std::endl;
}
else
{
std::cout <<"\nWindows Version konnte nicht ermittelt werden. " << std::endl;
initerfolg = false;
}
}
}
void chksys::readbit()
{
/** private Funktion: prüft ob eine x64 oder x32 Datei vorhanden ist**/
genbit();
std::fstream in64("x64.txt", std::ios::in);
std::fstream in32("x32.txt", std::ios::in);
if (in64.good())
{
bit = 64;
std::cout << " x" << bit << std::endl;
in64.close();
in32.close();
initerfolg = true;
}
if (in32.good())
{
bit = 32;
std::cout << " x" << bit << std::endl;
in64.close();
in32.close();
initerfolg = true;
}
if (in32.good()==false&&in64.good()==false)
{
std::cout << "- Architektur unbekannt!" << std::endl;
initerfolg = false;
}
}
void chksys::genbit(void)
{
/** private Funktion: generiert eine BAT Datei, führt diese aus und löscht dann diese **/
{
std::ofstream batch;
std::string bitline1{"@echo off"};
std::string bitline2{"reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v PROCESSOR_ARCHITECTURE | find /i \"x86\" > nul"};
std::string bitline3{"if \%errorlevel\%==0 ("};
std::string bitline4{" echo 32-bit --> x32.txt"};
std::string bitline5{") else ("};
std::string bitline6{" echo 64-bit --> x64.txt"};
std::string bitline7{")"};
std::string befehl = bitline1 + "\n" + bitline2 + "\n" + bitline3 + "\n" + bitline4 + "\n" + bitline5 + "\n" + bitline6 + "\n" + bitline7 + "\n";
//Bat Datei erstellen
batch.open("bit.bat", std::ios::out);
if(!batch)
{
initerfolg = false;
}
batch << befehl;
batch.close();
system("bit.bat");
}
}
void chksys::INITchksys(void)
{
cleanup();
readwin();
readbit();
cleanup();
}
void chksys::cleanup(void)
{
system("DEL ""x64.txt""");
system("DEL ""x32.txt""");
system("DEL ""bit.bat""");
system("DEL ""ver.txt""");
system("DEL ""ver.bat""");
}
int chksys::getwin(void)
{
if(initerfolg==false)return 0;
return win;
}
int chksys::getbit(void)
{
if(initerfolg==false)return 0;
return bit;
}
bool chksys::getver(void)
{
if(initerfolg==false)return false;
return aktver;
}
std::string chksys::getcompletever(void)
{
if(initerfolg==false)return "FEHLER";
return readstring;
}