如何判断电脑是32位还是64位?

发布于 2024-11-14 06:48:13 字数 60 浏览 5 评论 0原文

如何确定您使用的计算机是 32 位机器还是 64 位机器?

我最好用 vba 来完成这个。

How do you determine if the computer you are on is a 32-bit machine or a 64-bit machine?

I need this done in vba preferrably.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

岁月染过的梦 2024-11-21 06:48:13

@Wouter Simon 的答案有点正确,但确实不完整。它缺少一些 Declare 语句以及某种解释。

因此,我认为值得在这里展示一个更完整、更有效的版本。

Private Declare Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long '()

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function IsWow64Process Lib "kernel32" _
    (ByVal hProcess As Long, ByRef Wow64Process As Long) As Long

Sub CheckWhetherIts64()

    Dim Its64 As Long
    Dim handle As Long

    handle = GetProcAddress(GetModuleHandle("kernel32"), _
                   "IsWow64Process")

    If handle > 0 Then ' IsWow64Process function exists
        ' Now use the function to determine if
        ' we are running under Wow64

        IsWow64Process GetCurrentProcess(), Its64
    End If
    If Its64 = 1 Then
        MsgBox "it's a 64 bit process."
    End If
End Sub

注意事项:

为了兼容不支持该功能的操作系统,请调用GetProcAddress检测Kernel32.dll中是否实现了IsWow64Process。如果 GetProcAddress 成功,则可以安全地调用此函数。否则,WOW64 不存在。请注意,此技术并不是检测操作系统是否为 64 位版本 Windows 的可靠方法,因为当前版本的 32 位 Windows 中的 Kernel32.dll 也包含此函数。

http://msdn.microsoft.com/en -us/library/ms684139%28v=vs.85%29.aspx

@Wouter Simon's answer is sort of on the right track, but really incomplete. It is missing a couple of Declare statements as well as some kind of explanation.

Therefore I believe it's worth presenting a more complete and working version here.

Private Declare Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long '()

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function IsWow64Process Lib "kernel32" _
    (ByVal hProcess As Long, ByRef Wow64Process As Long) As Long

Sub CheckWhetherIts64()

    Dim Its64 As Long
    Dim handle As Long

    handle = GetProcAddress(GetModuleHandle("kernel32"), _
                   "IsWow64Process")

    If handle > 0 Then ' IsWow64Process function exists
        ' Now use the function to determine if
        ' we are running under Wow64

        IsWow64Process GetCurrentProcess(), Its64
    End If
    If Its64 = 1 Then
        MsgBox "it's a 64 bit process."
    End If
End Sub

Caveat:

For compatibility with operating systems that do not support this function, call GetProcAddress to detect whether IsWow64Process is implemented in Kernel32.dll. If GetProcAddress succeeds, it is safe to call this function. Otherwise, WOW64 is not present. Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function.

http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

贪恋 2024-11-21 06:48:13

从那里得到的
http://www.msoffice.us/Access/PDF/Extending %20VBA%20with%20APIs.pdf。看来它正在我的身上发挥作用。

Option Compare Database

Type SYSTEM_INFO
wProcessorArchitecture As Integer
wReserved As Integer
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End Type

Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Declare Function GetCurrentProcess Lib "kernel32" () As Long

Public Function Is64BitProcessor() As Boolean
Const PROCESSOR_ARCHITECTURE_AMD64 As Integer = 9
Const PROCESSOR_ARCHITECTURE_IA64 As Integer = 6
Dim si As SYSTEM_INFO
' call the API
GetNativeSystemInfo si
' check the struct
Is64BitProcessor = (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 _
Or _
si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64)
End Function

http://msdn.microsoft.com/en-我们/library/ms724340(v=vs.85).aspx

got it from
http://www.msoffice.us/Access/PDF/Extending%20VBA%20with%20APIs.pdf. Seems like it is working on mine.

Option Compare Database

Type SYSTEM_INFO
wProcessorArchitecture As Integer
wReserved As Integer
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End Type

Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Declare Function GetCurrentProcess Lib "kernel32" () As Long

Public Function Is64BitProcessor() As Boolean
Const PROCESSOR_ARCHITECTURE_AMD64 As Integer = 9
Const PROCESSOR_ARCHITECTURE_IA64 As Integer = 6
Dim si As SYSTEM_INFO
' call the API
GetNativeSystemInfo si
' check the struct
Is64BitProcessor = (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 _
Or _
si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64)
End Function

http://msdn.microsoft.com/en-us/library/ms724340(v=vs.85).aspx

ˇ宁静的妩媚 2024-11-21 06:48:13

要确定正在运行的 Office 是 64 位还是 32 位:
使用 IsWow64Process(Jean-François Corbett 的回答)。

要确定 Windows 是 64 位还是 32 位:

Public Function isWin64bit() As Boolean
  isWin64bit = 0 < Len(Environ("ProgramW6432"))
End Function

To determine whether the running Office is 64-bit or 32-bit:
Use IsWow64Process (answer from Jean-François Corbett).

To determine whether Windows is 64-bit or 32-bit:

Public Function isWin64bit() As Boolean
  isWin64bit = 0 < Len(Environ("ProgramW6432"))
End Function
银河中√捞星星 2024-11-21 06:48:13

我认为最直接的方法是:

#If Win64 Then
    MsgBox "Win 64"
#Else
    MsgBox "Win 32"
#End If

有时检查您的Office是32位还是64位并使用此信息访问注册表中的正确密钥也很有用。所以你可以这样做:

#If Win64 Then
    #If VBA7 Then
        MsgBox "Win 64 and Office 64" ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
    #Else
        MsgBox "Win 64 and Office 32" ' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\YourApp
    #End If
#Else
    MsgBox "Win 32 and Office 32" ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
#End If

HTH

I think the most straightforward way is:

#If Win64 Then
    MsgBox "Win 64"
#Else
    MsgBox "Win 32"
#End If

Sometimes it is also useful to check whether your Office is 32 or 64 and use this information to access the correct key in registry. So you can do:

#If Win64 Then
    #If VBA7 Then
        MsgBox "Win 64 and Office 64" ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
    #Else
        MsgBox "Win 64 and Office 32" ' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\YourApp
    #End If
#Else
    MsgBox "Win 32 and Office 32" ' HKEY_LOCAL_MACHINE\SOFTWARE\YourApp
#End If

HTH

土豪 2024-11-21 06:48:13

条件编译可能非常有用,WinXX 检测环境但不检测硬件属性,示例如下:

   Dim mVers   As String

Sub Init()

    #If Win64 Then
        mVers = "Win64" ' Win64=true, Win32=true, Win16= false
        Call VerCheck
    #ElseIf win32 Then
        mVers = "Win32"  ' Win32=true, Win16=false
        Call VerCheck
    #ElseIf win16 Then
        mVers = "Win16"  ' Win16=true
        Call VerCheck
    #End If

End Sub

Sub VerCheck()
    MsgBox "Version: " & mVers, vbInformation, "Version"
End Sub

Conditional compilation could be very useful, WinXX detects environment but not hardware properties, example below :

   Dim mVers   As String

Sub Init()

    #If Win64 Then
        mVers = "Win64" ' Win64=true, Win32=true, Win16= false
        Call VerCheck
    #ElseIf win32 Then
        mVers = "Win32"  ' Win32=true, Win16=false
        Call VerCheck
    #ElseIf win16 Then
        mVers = "Win16"  ' Win16=true
        Call VerCheck
    #End If

End Sub

Sub VerCheck()
    MsgBox "Version: " & mVers, vbInformation, "Version"
End Sub
素罗衫 2024-11-21 06:48:13

我认为 VBA 可能与正在运行的 Office 版本相关联,并且正在运行的进程类型确实很重要。此代码片段可能有帮助(VB6代码)

Private Declare Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" _

handle = GetProcAddress(GetModuleHandle("kernel32"), _
               "IsWow64Process")

If handle > 0 Then ' IsWow64Process function exists
    ' Now use the function to determine if 
    ' we are running under Wow64
    IsWow64Process GetCurrentProcess(), bolFunc
End If

I think VBA may be linked to the office version that is running and it really matters what type of process is running. This code snippet may help (VB6 code)

Private Declare Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" _

handle = GetProcAddress(GetModuleHandle("kernel32"), _
               "IsWow64Process")

If handle > 0 Then ' IsWow64Process function exists
    ' Now use the function to determine if 
    ' we are running under Wow64
    IsWow64Process GetCurrentProcess(), bolFunc
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文