check OS and processor is 32 bit or 64 bit?

后端 未结 5 2003
谎友^
谎友^ 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:03

    The most straightforward way to answer both questions seems to be using Win32_Processor WMI class.


    Is operating system 32-bit or 64-bit?

    For operating system one can check AddressWidth property:

    AddressWidth

    On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64.

    Relevant VB6 code is:

    Public Function GetOsBitness() As String
        Dim ProcessorSet As Object
        Dim CPU As Object
    
        Set ProcessorSet = GetObject("Winmgmts:"). _
            ExecQuery("SELECT * FROM Win32_Processor")
        For Each CPU In ProcessorSet
            GetOsBitness = CStr(CPU.AddressWidth)
        Next
    End Function
    

    Is processor 32-bit or 64-bit?

    For processor one can check DataWidth property:

    DataWidth

    On a 32-bit processor, the value is 32 and on a 64-bit processor it is 64.

    Relevant VB6 code is:

    Public Function GetCpuBitness() As String
        Dim ProcessorSet As Object
        Dim CPU As Object
    
        Set ProcessorSet = GetObject("Winmgmts:"). _
            ExecQuery("SELECT * FROM Win32_Processor")
        For Each CPU In ProcessorSet
            GetCpuBitness = CStr(CPU.DataWidth)
        Next
    End Function
    

提交回复
热议问题