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 hProc As Long, bWow64Process As Boolean) As Long
Private Declare Function GetSystemWow64Directory Lib "kernel32.dll" Alias "GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal uSize As Long) As Long
Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32" (ByVal oldvalue As Long) As Boolean
Option Explicit
Private Sub main()
Dim lWow64RedirectReturn As Long: lWow64RedirectReturn = 0
Dim ret As Boolean
Dim is64 As Boolean: is64 = Is64bitOS
Debug.Print "Is OS 64-bit? " & is64
If is64 Then ret = Wow64DisableWow64FsRedirection(lWow64RedirectReturn)
Debug.Print "API = " & ret
CheckRedirection
GetLinkTarget
If is64 Then ret = Wow64RevertWow64FsRedirection(lWow64RedirectReturn)
Debug.Print "API = " & ret
CheckRedirection
GetLinkTarget
End Sub
Public Function Is64bitOS() As Boolean
Dim bWow64Process As Boolean
Dim handle As Long: handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process") ' if IsWow64Process function exists
If handle > 0 Then IsWow64Process GetCurrentProcess(), bWow64Process ' Is running under Wow64
Is64bitOS = bWow64Process
End Function
Sub CheckRedirection()
Dim exe: exe = Environ("SystemRoot") & "\system32\msg.exe"
Debug.Print "Redirect = " & (Dir$(exe, vbReadOnly Or vbSystem Or vbHidden) <> vbNullString)
End Sub
Sub GetLinkTarget()
Dim Link: Link = "C:\Users\Alex\Desktop\IE.lnk"
Dim oLink: Set oLink = CreateObject("WScript.Shell").CreateShortcut(Link)
Debug.Print oLink.TargetPath
'Debug.Print oLink.WorkingDirectory
End Sub