以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  可以获取硬件更多信息么  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=113855)

--  作者:煜杭
--  发布时间:2018/1/24 10:47:00
--  可以获取硬件更多信息么
If HardWareInfo.Ready = False \'如果没有初始化
    HardWareInfo.Initialize \'初始化HardWareInfo,提取硬件信息
End If

Output.Show(
"CPU信息")
With
 HardWareInfo.CPU
    Output.Show(
"制造商:" & .Manufacturer)
    Output.Show(
"品名:" & .Name)
    Output.Show(
"型号:" & .Description)
    Output.Show(
"序列号:" & .ProcessorId)
End
 With
Output.Show(Chr(
13) & Chr(10))
Output.Show(
"主板信息")
With
 HardWareInfo.BaseBoard
    Output.Show(
"制造商:" & .Manufacturer)
    Output.Show(
"型号:" & .Product)
    Output.Show(
"序列号:" & .SerialNumber)
End
 With
Output.Show(Chr(
13) & Chr(10))
Output.Show(
"硬盘信息")
With
 HardWareInfo.Disk
    Output.Show(
"型号:" & .Model)
    Output.Show(
"序列号:" & .Signature)
End
 With
Output.Show(Chr(
13) & Chr(10))
Output.Show(
"BIOS信息")
With
 HardWareInfo.Bios
    Output.Show(
"厂商:" & .Manufacturer)
    Output.Show(
"序列号:" & .SerialNumber)
End
 With

想获取硬盘容量,内存容量要怎么写?
--  作者:有点甜
--  发布时间:2018/1/24 11:43:00
--  

mark 硬件信息

 

全局代码

 

Public Class commonUtlity
Public Shared Function ToGB(ByVal size As Double, ByVal m As Double) As String
Dim units As String() = New String() {"B", "KB", "MB", "GB", "TB", "PB"}
Dim i As Integer = 0
Do While size >= M
    size /= M
    i+=1
Loop
Return Math.Round(size) & units(i)
End Function
End Class

Public Enum WindowsAPIKeys
Name
VideoProcessor
AdapterRAM
ScreenWidth
ScreenHeight
Version
Size
Capacity
NumberOfCores
End Enum

Public Enum WindowsAPIType
Win32_PhysicalMemory
Win32_Processor
win32_DiskDrive
Win32_ComputerSystemProduct
Win32_DesktopMonitor
Win32_VideoController
Win32_OperatingSystem
End Enum

Public Class Computer

Private Shared _instance As Computer

Private Shared ReadOnly _lock As Object = New Object()

Private Sub New()
End Sub

Public Shared Function CreateComputer() As Computer
If _instance Is Nothing Then
    SyncLock _lock
    If _instance Is Nothing Then
        _instance = New Computer()
    End If
   
End SyncLock
End If

Return _instance
End Function

Public Function GetCPU() As Dictionary(Of String, String)
Dim result As new Dictionary(Of String, String)
Try
    Dim str As String = String.Empty
    Dim mcCPU As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.Win32_Processor.ToString())
    Dim mocCPU As System.Management.ManagementObjectCollection = mcCPU.GetInstances()
    For Each m As System.Management.ManagementObject In mocCPU
        Dim name As String = m(WindowsAPIKeys.Name.ToString()).ToString()
        Dim parts As String() = name.Split("@"c)
        result.add(parts(0).Split("-"c)(0) & "处理器", parts(1))
        Exit For
    Next
    Catch
End Try

Return result
End Function

Public Function GetCPU_Count() As String
Dim str As String = "查询失败"
Try
    Dim coreCount As Integer = 0
    For Each item As object In New System.Management.ManagementObjectSearcher("Select * from " & WindowsAPIType.Win32_Processor.ToString()).[Get]()
        coreCount += Integer.Parse(item(WindowsAPIKeys.NumberOfCores.ToString()).ToString())
    Next
   
    If coreCount = 2 Then
        Return "双核"
    End If
   
    str = coreCount.ToString() & "核"
    Catch
End Try

Return str
End Function

Public Function GetPhisicalMemory() As String
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
While em.MoveNext()
    Dim baseObj As object= em.Current
    If baseObj.Properties(WindowsAPIKeys.Capacity.ToString()).Value IsNot Nothing Then
        Try
            capacity += Long.Parse(baseObj.Properties(WindowsAPIKeys.Capacity.ToString()).Value.ToString())
            Catch
            Return "查询失败"
        End Try
    End If
End While

Return CommonUtlity.ToGB(CDbl(capacity), 1024)
End Function

Public Function GetDiskSize() As String
Dim result As String = String.Empty
Dim sb As StringBuilder = New StringBuilder()
Try
    Dim hdId As String = String.Empty
    Dim hardDisk As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.win32_DiskDrive.ToString())
    Dim hardDiskC As System.Management.ManagementObjectCollection = hardDisk.GetInstances()
    For Each m As System.Management.ManagementObject In hardDiskC
        Dim capacity As Long = Convert.ToInt64(m(WindowsAPIKeys.Size.ToString()).ToString())
        sb.Append(CommonUtlity.ToGB(capacity, 1000) & "+")
    Next
   
    result = sb.ToString().TrimEnd("+"c)
    Catch
End Try

Return result
End Function

Public Function GetVersion() As String
Dim str As String = "查询失败"
Try
    Dim hdId As String = String.Empty
    Dim hardDisk As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.Win32_ComputerSystemProduct.ToString())
    Dim hardDiskC As System.Management.ManagementObjectCollection = hardDisk.GetInstances()
    For Each m As System.Management.ManagementObject In hardDiskC
        str = m(WindowsAPIKeys.Version.ToString()).ToString()
        Exit For
    Next
    Catch
End Try

Return str
End Function

Public Function GetFenbianlv() As String
Dim result As String = "1920*1080"
Try
    Dim hdId As String = String.Empty
    Dim hardDisk As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.Win32_DesktopMonitor.ToString())
    Dim hardDiskC As System.Management.ManagementObjectCollection = hardDisk.GetInstances()
    For Each m As System.Management.ManagementObject In hardDiskC
        result = m(WindowsAPIKeys.ScreenWidth.ToString()).ToString() & "*" + m(WindowsAPIKeys.ScreenHeight.ToString()).ToString()
        Exit For
    Next
    Catch
End Try

Return result
End Function

Public Function GetVideoController() As Dictionary(Of String, String)
Dim result As new Dictionary(Of String, String)
Try
    Dim hardDisk As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.Win32_VideoController.ToString())
    Dim hardDiskC As System.Management.ManagementObjectCollection = hardDisk.GetInstances()
    For Each m As System.Management.ManagementObject In hardDiskC
        result.add(m(WindowsAPIKeys.VideoProcessor.ToString()).ToString().Replace("Family", ""), CommonUtlity.ToGB(Convert.ToInt64(m(WindowsAPIKeys.AdapterRAM.ToString()).ToString()), 1024))
        Exit For
    Next
    Catch
End Try

Return result
End Function

Public Function GetOS_Version() As String
Dim str As String = "Windows 10"
Try
    Dim hdId As String = String.Empty
    Dim hardDisk As System.Management.ManagementClass = New System.Management.ManagementClass(WindowsAPIType.Win32_OperatingSystem.ToString())
    Dim hardDiskC As System.Management.ManagementObjectCollection = hardDisk.GetInstances()
    For Each m As System.Management.ManagementObject In hardDiskC
        str = m(WindowsAPIKeys.Name.ToString()).ToString().Split("|"c)(0).Replace("Microsoft", "")
        Exit For
    Next
    Catch
End Try

Return str
End Function
End Class

 

调用代码

 

Dim dic = Computer.CreateComputer.getCPU
For Each key As String In dic.keys
    output.show(key & ":" & dic(key))
Next
dic = Computer.CreateComputer.GetVideoController
For Each key As String In dic.keys
    output.show(key & ":" & dic(key))
Next
Dim str = Computer.CreateComputer.GetCPU_Count
output.show(str)
str = Computer.CreateComputer.GetPhisicalMemory
output.show(str)
str = Computer.CreateComputer.GetDiskSize
output.show(str)
str = Computer.CreateComputer.GetVersion
output.show(str)

str = Computer.CreateComputer.GetFenbianlv
output.show(str)
str = Computer.CreateComputer.GetOS_Version
output.show(str)

 

添加dll引用

 

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20180124114152.png
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2018/1/24 11:44:00
--  

参考资料 https://www.cnblogs.com/wolf-sun/p/7153984.html

 


--  作者:煜杭
--  发布时间:2018/1/24 13:11:00
--  
感谢 
--  作者:ycwk
--  发布时间:2018/11/16 14:58:00
--  
能否读取到C盘剩余空间?
--  作者:有点甜
--  发布时间:2018/11/16 15:49:00
--  
以下是引用ycwk在2018/11/16 14:58:00的发言:
能否读取到C盘剩余空间?

 

Dim dk As New System.IO.DriveInfo("c:")
Return dk.TotalFreeSpace

 

https://docs.microsoft.com/zh-cn/dotnet/api/system.io.driveinfo?view=netframework-4.7.2

 


--  作者:ycwk
--  发布时间:2018/11/18 12:15:00
--  
了解,谢谢!  请问是否可能读取到可用内存的大小呢? 因为有时候发现第三方程序运行出问题,是内存消耗完毕,可用内存过小的原因。 
--  作者:有点甜
--  发布时间:2018/11/18 23:26:00
--  

output.show(sysinfo.AvailablePhysicalMemory)
output.show(sysinfo.ChineseScript )
output.show(sysinfo. ComputerName )
output.show(sysinfo. ConnectName )
output.show(sysinfo. ConnectType )
output.show(sysinfo. ConvertScript)
output.show(sysinfo. FileIdentify )
output.show(sysinfo. FormatCode )
output.show(sysinfo. ImportsStrings)
output.show(sysinfo. OSFullName )
output.show(sysinfo. OSVersion )
output.show(sysinfo. PublishFiles)
output.show(sysinfo. referFiles )
output.show(sysinfo. ScreenDpiX )
output.show(sysinfo. ScreenDpiY )
output.show(sysinfo.ScreenHeight )
output.show(sysinfo. ScreenWidth )
output.show(sysinfo. SourceString10)
output.show(sysinfo. SourceString4 )
output.show(sysinfo. spaceNames )
output.show(sysinfo.TotalPhysicalMemory )
output.show(sysinfo. UserName )
output.show(sysinfo. WorkingAreaHeight )
output.show(sysinfo.WorkingAreaWidth )


--  作者:zhutangxin
--  发布时间:2021/6/3 0:13:00
--  
Mark
--  作者:aidimeng
--  发布时间:2022/1/12 10:12:00
--  
可以使用在web上吗