Foxtable(狐表)用户栏目专家坐堂 → 可以获取硬件更多信息么


  共有5819人关注过本帖树形打印复制链接

主题:可以获取硬件更多信息么

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/1/24 11:44:00 [显示全部帖子]


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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 )


 回到顶部