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


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

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

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


加好友 发短信
等级:幼狐 帖子:97 积分:855 威望:0 精华:0 注册:2017/11/13 18:42:00
可以获取硬件更多信息么  发帖心情 Post By: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

想获取硬盘容量,内存容量要怎么写?

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | 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
图片点击可在新窗口打开查看

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


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


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


加好友 发短信
等级:幼狐 帖子:97 积分:855 威望:0 精华:0 注册:2017/11/13 18:42:00
  发帖心情 Post By:2018/1/24 13:11:00 [只看该作者]

感谢 

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


加好友 发短信
等级:六尾狐 帖子:1228 积分:8561 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/11/16 14:58:00 [只看该作者]

能否读取到C盘剩余空间?

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | 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

 


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


加好友 发短信
等级:六尾狐 帖子:1228 积分:8561 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/11/18 12:15:00 [只看该作者]

了解,谢谢!  请问是否可能读取到可用内存的大小呢? 因为有时候发现第三方程序运行出问题,是内存消耗完毕,可用内存过小的原因。 

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | 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 )


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


加好友 发短信
等级:一尾狐 帖子:465 积分:3983 威望:0 精华:0 注册:2016/10/14 13:40:00
  发帖心情 Post By:2021/6/3 0:13:00 [只看该作者]

Mark

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


加好友 发短信
等级:三尾狐 帖子:798 积分:7677 威望:0 精华:0 注册:2015/9/14 14:26:00
  发帖心情 Post By:2022/1/12 10:12:00 [只看该作者]

可以使用在web上吗

 回到顶部
总数 12 1 2 下一页