-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRAMStats.cs
174 lines (158 loc) · 5.91 KB
/
RAMStats.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
using System.Windows.Forms;
/// <summary>
/// Author: Mateusz Peplinski
/// Date v .10 Published: 01 / 08 / 2021
/// License: MIT
/// © 2021 Mateusz Peplinski
/// </summary>
//This class is created with the help of WMI code Creator v1.0
// https://www.microsoft.com/en-us/download/details.aspx?id=8572
// All methods here use Windows Management Instrumentation (WMI)
// they are called from root//CIMV2 and call methods from the Win32 API
namespace RUST
{
class RAMStats
{
public void RAMCapacity()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT TotalPhysicalMemory FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
double dblMemory;
if (double.TryParse(Convert.ToString(queryObj["TotalPhysicalMemory"]), out dblMemory))
{
Console.WriteLine("Total Physical Memory is: {0} MB", Convert.ToInt32(dblMemory / (1024 * 1024)));
Console.WriteLine("Total Physical Memory is: {0} GB", Convert.ToInt32(dblMemory / (1024 * 1024 * 1024)));
}
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void RAMArch()
{
int RAMSlotCounter = 0;
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DIMM {0} - TotalWidth: {1}", RAMSlotCounter, queryObj["TotalWidth"] + "bit");
RAMSlotCounter++;
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void RAMClockSpeed()
{
int RAMSlotCounter = 0;
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DIMM:{0} - Clock Speed: {1}", RAMSlotCounter, queryObj["ConfiguredClockSpeed"] + "Mhz");
RAMSlotCounter++;
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void RAMModel()
{
int RAMSlotCounter = 0;
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DIMM {0} - Manufacturer: {1}", RAMSlotCounter, queryObj["Manufacturer"]);
RAMSlotCounter++;
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void virtualMemName()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PageFileSetting");
Console.WriteLine("System Page File/s:");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void virtualMemEncryptionStat()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PageFile");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("Encrypted: {0}", queryObj["Encrypted"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
public void virtualMemSize()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PageFile");
foreach (ManagementObject queryObj in searcher.Get())
{
double dblVMemory;
if (double.TryParse(Convert.ToString(queryObj["FileSize"]), out dblVMemory))
{
Console.WriteLine("Page file Size is: {0} GB", Convert.ToInt32(dblVMemory / (1024 * 1024 * 1024)));
}
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}