자료실

부자는 돈을 써서 시간을 아끼지만 가난한 사람은 시간을 써서 돈을 아낀다

vb.net

IT HUB를 찾아주셔서 감사합니다.

기타 [vb.net] PlatformCheck

페이지 정보

profile_image
작성자 하나를하더라도최선을
댓글 0건 조회 7,129회 작성일 22-07-26 23:00

본문

Imports System
Imports System.Management
Imports System.Runtime.InteropServices
 
Public Class PlatformCheck
    Public Sub New()
        MyBase.New()
    End Sub
    Public Shared Function GetBinPath() As String
        Return String.Concat(If(PlatformCheck.Is64Bit(), "x64""x86"), "/appname.exe")
    End Function
    <DllImport("kernel32.dll", CharSet:=CharSet.None, ExactSpelling:=False)>
    Private Shared Function GetEnabledXStateFeatures() As Long
    End Function
    Public Shared Function GetSIMDAvailable() As PlatformCheck.SIMD
        Dim sIMD As PlatformCheck.SIMD
        Try
            If ((PlatformCheck.GetEnabledXStateFeatures() And CLng(4)) <> 0Then
                sIMD = PlatformCheck.SIMD.AVX
                Return sIMD
            End If
        Catch
        End Try
        Try
            If (PlatformCheck.IsProcessorFeaturePresent(13<> 0Then
                sIMD = PlatformCheck.SIMD.SSE3
            ElseIf (PlatformCheck.IsProcessorFeaturePresent(10<> 0Then
                sIMD = PlatformCheck.SIMD.SSE2
            ElseIf (PlatformCheck.IsProcessorFeaturePresent(6= 0Then
                Return PlatformCheck.SIMD.None
            Else
                sIMD = PlatformCheck.SIMD.SSE
            End If
        Catch
            Return PlatformCheck.SIMD.None
        End Try
        Return sIMD
    End Function
 
    Public Shared Function GetSystemInfo() As PlatformCheck.SystemInfo
        Dim systemInfo As PlatformCheck.SystemInfo = New PlatformCheck.SystemInfo()
        Using managementObjectSearcher As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher("select * from Win32_Processor")
            Using managementObjectSearcher1 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher("select * from Win32_ComputerSystem")
                Using managementObjectSearcher2 As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher("select * from Win32_OperatingSystem")
                    For Each managementObject As System.Management.ManagementObject In managementObjectSearcher.[Get]()
                        systemInfo.cpuClockSpeed = managementObject("MaxClockSpeed").ToString()
                        systemInfo.cpuName = managementObject("Name").ToString()
                        systemInfo.cpuManufacturer = managementObject("Manufacturer").ToString()
                        systemInfo.cpuVersion = managementObject("Version").ToString()
                    Next
                    For Each managementObject1 As System.Management.ManagementObject In managementObjectSearcher1.[Get]()
                        systemInfo.physicalMemory = Long.Parse(managementObject1("TotalPhysicalMemory").ToString())
                    Next
                    For Each managementObject2 As System.Management.ManagementObject In managementObjectSearcher2.[Get]()
                        systemInfo.osName = managementObject2("Caption").ToString()
                    Next
                End Using
            End Using
        End Using
        Return systemInfo
    End Function
 
    Public Shared Function GetUniqueComputerID() As String
        Dim empty As String = String.Empty
        Using enumerator As ManagementObjectCollection.ManagementObjectEnumerator = (New ManagementClass("win32_processor")).GetInstances().GetEnumerator()
            If (enumerator.MoveNext()) Then
                empty = DirectCast(enumerator.Current, System.Management.ManagementObject).Properties("processorID").Value.ToString()
            End If
        End Using
        Dim managementObject As System.Management.ManagementObject = New System.Management.ManagementObject(String.Concat("win32_logicaldisk.deviceid=""""C"":"""))
        managementObject.[Get]()
        Dim str As String = managementObject("VolumeSerialNumber").ToString()
        Return String.Concat(empty, "_", str)
    End Function
 
    Public Shared Function Is64Bit() As Boolean
        Return IntPtr.Size = 8
    End Function
 
    <DllImport("kernel32.dll", CharSet:=CharSet.None, ExactSpelling:=False)>
    Private Shared Function IsProcessorFeaturePresent(ByVal ProcessorFeature As Integer) As Integer
    End Function
 
    Public Enum SIMD
        None
        SSE
        SSE2
        SSE3
        AVX
    End Enum
 
    Public Class SystemInfo
        Public cpuClockSpeed As String
        Public cpuName As String
        Public cpuManufacturer As String
        Public cpuVersion As String
        Public physicalMemory As Long
        Public osName As String
        Public Sub New()
            MyBase.New()
        End Sub
    End Class
End Class
 

댓글목록

등록된 댓글이 없습니다.