منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
لمعرفة حجم الذاكرة الحية الخاصة بكل Slot - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : الأقسام التعليمية - المنتدى القديم (http://vb4arb.com/vb/forumdisplay.php?fid=90)
+--- قسم : مكتبة أكواد المنتدى (http://vb4arb.com/vb/forumdisplay.php?fid=111)
+---- قسم : مكتبة أكواد .net (http://vb4arb.com/vb/forumdisplay.php?fid=117)
+---- الموضوع : لمعرفة حجم الذاكرة الحية الخاصة بكل Slot (/showthread.php?tid=6266)



لمعرفة حجم الذاكرة الحية الخاصة بكل Slot - RaggiTech - 17-10-12

كاتب الموضوع : Boutemine Oualid

السلام عليكم ورحمة الله و بركاته
مثال آخر عن استعمال ال WMI

VB.NET

كود :
Private Function ListPhysicalMemory() As Collection
Dim Result As New Collection
Dim myScop As New Management.ManagementScope("\\" & Environment.MachineName & "\root\cimv2")
Dim oQuer As New Management.SelectQuery("SELECT * FROM Win32_PhysicalMemory")
Dim oResult As New Management.ManagementObjectSearcher(myScop, oQuer)
Dim oIte As Management.ManagementObject
Dim oPropert As Management.PropertyData
Dim StrFinal As String = Nothing
Dim Idx As Integer = 0
Try
Result.Clear()
For Each oIte In oResult.Get()
For Each oPropert In oIte.Properties
StrFinal &= oPropert.Name & " ---> "
If Not oPropert.Value Is Nothing Then StrFinal &= oPropert.Value
StrFinal &= vbCrLf
If Not oPropert.Value Is Nothing AndAlso oPropert.Name = "Capacity" Then
Dim Valeur As String = oPropert.Value
Result.Add(oPropert.Value, "Slot " & Idx)
End If
Next
Idx += 1
Next
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Erreur", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
Return Result
End Function
C#

كود :
public static string[] ListPhysicalMemory()
{
ManagementScope mscope = new ManagementScope(string.Format(@"[url=file://%7B0%7D/root/cimv2]\\{0}\root\cimv2[/url]", Environment.MachineName));
ManagementObjectSearcher mos = new ManagementObjectSearcher(mscope, new ObjectQuery("SELECT * FROM Win32_PhysicalMemory"));
StringBuilder szb = new StringBuilder();
foreach (ManagementObject mo in mos.Get())
szb.AppendFormat(@"{0}:{1};", mo.Properties["BankLabel"].Value, mo.Properties["Capacity"].Value);
mos.Dispose();

string szResult=szb.ToString().Trim();
return szResult.Remove(szResult.Length - 1).Split(";".ToCharArray());
}