check OS and processor is 32 bit or 64 bit?

后端 未结 5 2005
谎友^
谎友^ 2021-01-19 10:09

I want vb6 code to check OS is 32 bit or 64 bit and also processor is 32 bit or 64 bit.So please help me to get these codes. In vb.net i can use Environment.Is64BitOperating

5条回答
  •  佛祖请我去吃肉
    2021-01-19 11:00

    Operating system architecture

    One way to obtain it is to use GetNativeSystemInfo WinAPI function. It is covered in linked question.

    OS architecture can be obtained through WMI too, in case you'd like to achieve both goals in similar way. In Windows Vista and newer operating systems one can query Win32_OperatingSystem class and analyze OSArchitecture property (MSDN). Sadly, this property doesn't exist in Windows XP and earlier versions. On these systems one may query Win32_ComputerSystem class and analyze SystemType property instead (MSDN).

    Public Function GetOsArchitecture()
        If IsAtLeastVista Then
            GetOsArchitecture = GetVistaOsArchitecture
        Else
            GetOsArchitecture = GetXpOsArchitecture
        End If
    End Function
    
    Private Function IsAtLeastVista() As Boolean
        IsAtLeastVista = GetOsVersion >= "6.0"
    End Function
    
    Private Function GetOsVersion() As String
        Dim OperatingSystemSet As Object
        Dim OS As Object
    
        Set OperatingSystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                                        InstancesOf("Win32_OperatingSystem")
        For Each OS In OperatingSystemSet
            GetOsVersion = Left$(Trim$(OS.Version), 3)
        Next
    End Function
    
    Private Function GetVistaOsArchitecture() As String
        Dim OperatingSystemSet As Object
        Dim OS As Object
    
        Set OperatingSystemSet = GetObject("Winmgmts:"). _
            ExecQuery("SELECT * FROM Win32_OperatingSystem")
        For Each OS In OperatingSystemSet
            GetVistaOsArchitecture = Left$(Trim$(OS.OSArchitecture), 2)
        Next
    End Function
    
    Private Function GetXpOsArchitecture() As String
        Dim ComputerSystemSet As Object
        Dim Computer As Object
        Dim SystemType As String
    
        Set ComputerSystemSet = GetObject("Winmgmts:"). _
            ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For Each Computer In ComputerSystemSet
            SystemType = UCase$(Left$(Trim$(Computer.SystemType), 3))
        Next
    
        GetXpOsArchitecture = IIf(SystemType = "X86", "32", "64")
    End Function
    

提交回复
热议问题