以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]请问下读取内存信息报错是什么原因呢  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=143040)

--  作者:81538475
--  发布时间:2019/11/12 12:35:00
--  [求助]请问下读取内存信息报错是什么原因呢
Dim searcher As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher()
searcher.Query = New System.Management.SelectQuery(WindowsAPIType.Win32_PhysicalMemory.ToString(), "", New String() {WindowsAPIKeys.Capacity.ToString()})
Dim collection As System.Management.ManagementObjectCollection = searcher.[Get]()
Dim em As System.Management.ManagementObjectCollection.ManagementObjectEnumerator = collection.GetEnumerator()
Dim capacity As Long = 0
Dim i As Integer =0
Dim all2 As String
For Each mo As object In moc
    capacity =  Long.Parse(mo.Properties(WindowsAPIKeys.Capacity.ToString()).Value.ToString())
    i=i+1
 
    For i2 As Integer = 1 To i
    Dim ddr As String =""
    If mo.Properties("SMBIOSMemoryType").Value.ToString()  = 26 Then
     ddr = "DDR4"
    Else
     ddr=mo.Properties("SMBIOSMemoryType").Value.ToString()
    End If
        msgbox("内存" & I & ": " & "  "& capacity/1024/1024/1024 & "GB")
        ALL2 = "内存" & I & ": " & mo.Properties("Manufacturer").Value.ToString() & " " &  mo.Properties("speed").Value.ToString() &  " 参数:" & capacity/1024/1024/1024 & "GB" & "|"

Next
Next
下面是搜集的报错信息

Not found 
   在 Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
   在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure, Boolean[] CopyBack)
   在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   在 Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   在 UserCode.AU0uMyq1TH4xAAWIK(ControlEventArgs e)



--  作者:有点蓝
--  发布时间:2019/11/12 13:44:00
--  
没有WindowsAPIType这种类型,抄代码抄完整
--  作者:81538475
--  发布时间:2019/11/12 14:04:00
--  
Public Enum WindowsAPIType
Win32_PhysicalMemory
Win32_Processor
win32_DiskDrive
Win32_ComputerSystemProduct
Win32_DesktopMonitor
Win32_VideoController
Win32_OperatingSystem
End Enum
忘记贴全局变量了

--  作者:有点蓝
--  发布时间:2019/11/12 14:32:00
--  
代码不完整,无法测试