17-10-12, 06:17 PM
كاتب الموضوع : 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
كود :
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());
}