-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
253 lines (218 loc) · 7.92 KB
/
Form1.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
namespace EWSS_C
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
PreInit();
}
// ÈÍÈÖÈÀËÈÇÀÖÈß
public static class Globals // ÃËÎÁÀËÜÍÛÅ ÏÅÐÅÌÅÍÍÛÅ
{
public static string selected_kms = "0.0.0.0";
}
public void PreInit()
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
//GetNetworkII();
UpdateVersionInfo();
toolStripStatusLabel1.Text = "Èíèöèàëèçîâàí";
}
// ÔÓÍÊÖÈÈ ÈÍÈÖÈÀËÈÇÀÖÈÈ
private string GetRegValue(string subkey, string value)
{
try
{
using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(subkey, false)) // False is important!
{
var s = key?.GetValue(value) as string;
if (!string.IsNullOrWhiteSpace(s))
{
return s;
}
else return "0";
}
}
catch (Exception ex) //just for demonstration...it's always best to handle specific exceptions
{
return "-1";
}
}
private void UpdateVersionInfo()
{
label1.Text = GetRegValue("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName");
label2.Text = GetRegValue("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "EditionID");
label1.Visible = true;
label2.Visible = true;
}
/**private void GetNetworkII()
{
foreach (System.Net.NetworkInformation.NetworkInterface nic in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
comboBox1.Items.Add(nic.Name);
}
}**/
// ÑËÓÆÅÁÍÛÅ ÔÓÍÊÖÈÈ
private void Execute(string file)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
//string command = "Get-NetAdapter | Format-Table -Property Name";
process.StartInfo.FileName = file;
//process.StartInfo.Arguments = command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.Start();
}
catch (System.ComponentModel.Win32Exception)
{
MessageBox.Show("Äëÿ âûïîëíåíèÿ îïåðàöèè òðåáóþòñÿ ïðàâà àäìèíèñòðàòîðà");
}
}
private void PSExecute(string command)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
//string command = "Get-NetAdapter | Format-Table -Property Name";
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
}
private void CMDExecute(string command)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = command;
process.StartInfo = startInfo;
process.StartInfo.RedirectStandardOutput = false;
process.Start();
}
private string CMDExecuteOutStr(string command)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = command;
process.StartInfo = startInfo;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
return process.StandardOutput.ReadLine();
}
private static bool PingHost(string nameOrAddress)
{
bool pingable = false;
using (var pinger = new System.Net.NetworkInformation.Ping())
{
try
{
System.Net.NetworkInformation.PingReply reply = pinger.Send(nameOrAddress);
pingable = reply.Status == System.Net.NetworkInformation.IPStatus.Success;
}
catch (System.Net.NetworkInformation.PingException)
{
return false;
}
finally
{
if (pinger != null)
{
pinger.Dispose();
}
}
return pingable;
}
}
private string KMSCheck()
{
bool kms1 = false;
bool kms2 = false;
string kms1_ip = "kms8.msguides.com";
string kms2_ip = "kms9.msguides.com";
string none_ip = "0.0.0.0";
label4.Text = kms1_ip;
label5.Text = kms2_ip;
//KMS1
if (PingHost(kms1_ip) == true)
{
pictureBox3.Image = imageList1.Images[0];
kms1 = true;
}
else
{
pictureBox3.Image = imageList1.Images[1];
}
//KMS2
if (PingHost(kms2_ip) == true)
{
pictureBox4.Image = imageList1.Images[0];
kms2 = true;
}
else
{
pictureBox4.Image = imageList1.Images[1];
}
if (kms1 == true && kms2 == true)
{
label4.Font = new Font(this.Font, FontStyle.Bold);
return kms1_ip;
}
else if (kms1 == true && kms2 == false)
{
label4.Font = new Font(this.Font, FontStyle.Bold);
return kms1_ip;
}
else if (kms1 == false && kms2 == true)
{
label5.Font = new Font(this.Font, FontStyle.Bold);
return kms2_ip;
}
else
{
label5.Font = new Font(this.Font, FontStyle.Bold);
return none_ip;
}
}
private void button1_Click(object sender, EventArgs e)
{
Execute("cmd");
}
private void button2_Click(object sender, EventArgs e)
{
Execute("powershell");
}
private void button3_Click(object sender, EventArgs e)
{
Execute("regedit");
}
private void button4_Click(object sender, EventArgs e)
{
Execute("SystemPropertiesAdvanced.exe");
}
private void button5_Click(object sender, EventArgs e)
{
Execute("UserAccountControlSettings.exe");
}
private void button6_Click(object sender, EventArgs e)
{
Execute("control");
}
private void button7_Click(object sender, EventArgs e)
{
Execute("msconfig");
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
label3.Text = "ÎÑ: " + listView1.FocusedItem.SubItems[0].Text;
textBox1.Text = listView1.FocusedItem.SubItems[1].Text;
Globals.selected_kms = KMSCheck();
}
}
}