Check OS and processor 32 bit or 64 bit?

I want the vb6 code to test the OS to be 32-bit or 64-bit, as well as a 32-bit or 64-bit processor. So please help me get these codes. In vb.net, I can use the Environment.Is64BitOperatingSystem property and only works in .net 4.0 and higher. But how can I get this information in vb6?

+4
source share
5 answers

For the CPU, you can use WMI and get the AddressWidth. VBScript sample can be found here.

+3
source

The easiest way to answer both questions seems to be to use the Win32_Processor WMI class.


Is the operating system 32-bit or 64-bit?

For the operating system, you can check the AddressWidth property:

AddressWidth

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

Corresponding VB6 code:

 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 the processor 32-bit or 64-bit?

For the processor, you can check the DataWidth property:

DataWidth

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

Corresponding VB6 code:

 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 
+3
source

You can try the DataWidth or AddressWidth properties of the DataWidth AddressWidth class; on a 32-bit processor, the value is 32, and on a 64-bit processor, 64.

+1
source

Operating system architecture

One way to get this is to use the GetNativeSystemInfo WinAPI function. It is addressed in a related issue .

The OS architecture can also be obtained through WMI if you want to achieve both goals in a similar way. On Windows Vista and newer operating systems, you can query the Win32_OperatingSystem class and analyze the OSArchitecture ( MSDN ) property. Unfortunately, this property does not exist in Windows XP and earlier versions. On these systems, you can query the Win32_ComputerSystem class and 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 
+1
source

On Windows Xp 32b, Win32_Processor.AddressWidth returns ALWAYS 32. See the message How does the MAP tool detect its 64-bit machine?

0
source

All Articles