-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathForm1.cs
299 lines (234 loc) · 11.5 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Management.Instrumentation;
using System.Security;
namespace WMI2
{
public partial class Form1 : Form
{
string ram_usage,kalann,toplam,total_disk,disk_space;
ConnectionOptions baglanti;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
servis_sorgula();
grafik_ciz_ram();
disk_grafik();
label40.Visible = true;
label44.Visible = true;
label39.Visible = true;
label52.Text = listBox6.Items.Count.ToString();
}
public void servis_sorgula()
{
try
{
/*Bağlantı yapılıyor*/
ConnectionOptions baglanti = new ConnectionOptions();
baglanti.Username = textBox3.Text;
baglanti.Password = textBox4.Text;
baglanti.Authority = "ntlmdomain:" + textBox2.Text;
if (textBox2.Text == "")
baglanti.Authority = "";
string path = "\\\\" + textBox1.Text + "\\root" + "\\CIMV2";
ManagementScope scope = new ManagementScope(
path, baglanti);
// MessageBox.Show("Bağlantı Kuruluyor.. Servis Listesi Alınıyor .....");
scope.Connect();
/*
Servis listesi için sorgu oluşturulup managementonjseacher nesnesi tanımlanıyor.
*/
MessageBox.Show("bağlandı","Bağlantı",MessageBoxButtons.OK,MessageBoxIcon.Information);
ObjectQuery sorgu = new ObjectQuery(
"SELECT * FROM Win32_Service");
ManagementObjectSearcher man_ob_arayici =
new ManagementObjectSearcher(scope, sorgu);
foreach (ManagementObject obj in man_ob_arayici.Get())
{
listBox1.Items.Add(obj["Name"].ToString());
}
label41.Text = listBox1.Items.Count.ToString();
/*
proccess bilgileri alınıyor.
*/
//MessageBox.Show("Bağlantı Kuruluyor.. Process Listesi Alınıyor .....");
ObjectQuery sorgu2 = new ObjectQuery("SELECT * FROM Win32_process");
ManagementObjectSearcher man_ob_arayici2 =
new ManagementObjectSearcher(scope, sorgu2);
foreach (ManagementObject obj in man_ob_arayici2.Get())
{
listBox2.Items.Add(obj["Name"].ToString());
}
label42.Text = listBox2.Items.Count.ToString();
//sistem bilgisi alınıyor
//MessageBox.Show("Bağlantı Kuruluyor.. Sistem Bilgisi Alınıyor .....");
ObjectQuery sorgu4 = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher man_ob_arayici4 = new ManagementObjectSearcher(scope, sorgu4);
foreach (ManagementObject obj in man_ob_arayici4.Get())
{
label6.Text = obj["Caption"].ToString();
label8.Text = obj["OSArchitecture"].ToString();
label10.Text = obj["SerialNumber"].ToString();
label12.Text = obj["Version"].ToString();
label21.Text = obj["SystemDirectory"].ToString();
string total = (Convert.ToInt64(obj["TotalVisibleMemorySize"]) / (1024)).ToString();
string kalan = (Convert.ToInt64(obj["FreePhysicalMemory"]) / (1024)).ToString();
string kullanılan = (Convert.ToInt64(total) - Convert.ToInt64(kalan)).ToString();
toplam = total;
kalann = kalan;
ram_usage = kullanılan;
label19.Text = kullanılan + " MB";
double yuzde = (Convert.ToDouble(Convert.ToDouble(kullanılan) / Convert.ToDouble(total)) * 100);
double a = Math.Round(yuzde, 2);
label15.Text = a.ToString() + " %";
}
//Donanım bilgileri alınıyor.
//MessageBox.Show("Bağlantı Kuruluyor.. Donanım Bilgileri Alınıyor .....");
ObjectQuery sorgu3 = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
ManagementObjectSearcher man_ob_arayici3 =
new ManagementObjectSearcher(scope, sorgu3);
foreach (ManagementObject obj in man_ob_arayici3.Get())
{
label18.Text = (obj["NumberOfLogicalProcessors"].ToString());
label14.Text = (Convert.ToInt64(obj["TotalPhysicalMemory"]) / (1024 * 1024)).ToString() + " MB";
label29.Text = obj["Manufacturer"].ToString();
label27.Text = obj["Model"].ToString();
label25.Text = obj["Name"].ToString();
}
//Bios bilgileri alınıyor.
//MessageBox.Show("Bağlantı Kuruluyor.. BİOS Bilgileri Alınıyor .....");
ObjectQuery sorgu5 = new ObjectQuery("SELECT * FROM Win32_BIOS");
ManagementObjectSearcher man_ob_arayici5 =
new ManagementObjectSearcher(scope, sorgu5);
foreach (ManagementObject obj in man_ob_arayici5.Get())
{
label23.Text = obj["Caption"].ToString();
label31.Text = obj["Manufacturer"].ToString();
label33.Text = obj["SerialNumber"].ToString();
}
//MessageBox.Show("cpu usage");
ObjectQuery sorgu6 = new ObjectQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor ");
ManagementObjectSearcher man_ob_arayici6 = new ManagementObjectSearcher(scope, sorgu6);
foreach (ManagementObject obj in man_ob_arayici6.Get())
{
listBox3.Items.Add(obj["PercentProcessorTime"].ToString());
listBox4.Items.Add(obj["Name"].ToString());
}
ObjectQuery sorgu7 = new ObjectQuery("SELECT HotFixID FROM Win32_QuickFixEngineering");
ManagementObjectSearcher man_ob_arayici7 = new ManagementObjectSearcher(scope, sorgu7);
foreach (ManagementObject obj in man_ob_arayici7.Get())
{
listBox6.Items.Add(obj["HotFixID"].ToString());
}
/* ObjectQuery sorgu7 = new ObjectQuery("SELECT * FROM Win32_Volume Where DriveLetter='C'");
ManagementObjectSearcher man_ob_arayici7 = new ManagementObjectSearcher(scope, sorgu7);
foreach (ManagementObject obj in man_ob_arayici7.Get())
{
int a = 1024 * 1024 * 1024;
long total_disk2 = Convert.ToInt64(obj["Size"].ToString())/a;
total_disk = total_disk2.ToString();
long disk_space2 = Convert.ToInt64(obj["SizeRemaining"].ToString())/a;
disk_space = disk_space2.ToString();
}
MessageBox.Show(total_disk.ToString());
MessageBox.Show(disk_space.ToString());
*/
/* ObjectQuery sorgu8 = new ObjectQuery("SELECT * FROM Win32_DiskDrive WHERE Model='" + label48.Text + "'");
ManagementObjectSearcher man_ob_arayici8 = new ManagementObjectSearcher(scope, sorgu8);
foreach (ManagementObject obj in man_ob_arayici8.Get())
{
//label48.Text = (obj["Model"].ToString());
total_disk = (Convert.ToInt64(obj["Size"]) / 1024).ToString() + " GB";
// disk_space = obj["FreeSpace"].ToString();
}
MessageBox.Show(disk_space);*/
}
catch (ManagementException hata)
{
MessageBox.Show("Sorgu alınırken hata oluştu: "
+ hata.Message);
}
catch (System.UnauthorizedAccessException login_hata)
{
MessageBox.Show("Bağlantı hatası " +
"(kullanıcı adı or parola hatalı): " +
login_hata.Message);
}
}
private void textBox2_Click(object sender, EventArgs e)
{
textBox2.Text = "";
}
private void label6_Click(object sender, EventArgs e)
{
}
private void chart1_Click(object sender, EventArgs e)
{
}
public void grafik_ciz_ram()
{
Pen p = new Pen(Color.Black, 1);
Graphics g = this.CreateGraphics();
Rectangle re = new Rectangle(450, 600 , 200, 200);
Color clr;
clr = new Color();
float aci1 = float.Parse(ram_usage)/float.Parse(toplam)*360;
float aci2 = float.Parse(kalann) / float.Parse(toplam) * 360;
Brush br1 = new SolidBrush(Color.Blue);
Brush br2 = new SolidBrush(Color.Red);
g.DrawPie(p, re, 0, aci1);
g.FillPie(br2, re, 0, aci1);
g.DrawPie(p, re, aci1, aci2);
g.FillPie(br1,re, aci1, aci2);
label40.Text = "Ram Kullanımı";
label39.Text = "Kullanılan:";
label44.Text = "Boşta";
label43.Text = ram_usage + " MB";
label45.Text = kalann + " MB";
for (int i = 0; i < listBox3.Items.Count; i++)
{
this.chart1.Series["Cpu_%"].Points.AddXY("Core " + listBox4.Items[i], listBox3.Items[i]);
if (listBox4.Items[i].ToString() == "_Total")
{ label47.Text = "%" + listBox3.Items[i].ToString();
label46.Text = "Cpu Kullanım : ";
}
}
chart1.Visible = true;
}
public void disk_grafik()
{
Pen p = new Pen(Color.Black, 1);
Graphics g = this.CreateGraphics();
Rectangle re = new Rectangle(150, 600, 200, 200);
Color clr;
clr = new Color();
float aci1 = float.Parse(ram_usage) / float.Parse(toplam) * 360;
float aci2 = float.Parse(kalann) / float.Parse(toplam) * 360;
Brush br1 = new SolidBrush(Color.RoyalBlue);
Brush br2 = new SolidBrush(Color.YellowGreen);
g.DrawPie(p, re, 0, aci1);
g.FillPie(br2, re, 0, aci1);
g.DrawPie(p, re, aci1, aci2);
g.FillPie(br1, re, aci1, aci2);
label50.Text = "Disk Kullanım ";
//label39.Text = "Kullanılan:";
//label44.Text = "Boşta";
//label43.Text = ram_usage + " MB";
//label45.Text = kalann + " MB";
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}