Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run programs from 64-bit system folder (disable redirection)
One day you'll find that QM run() function does not find some programs that are in system folder (c:\windows\system32 or $system$). It happens on 64-bit Windows. It is because of file system redirection, when the program exists in the 64-bit folder (System32) but not in the 32-bit folder (SysWOW64). There are several ways to run 64-bit system programs.

1. QM In most cases run() detects when the 32-bit system program does not exist, and then runs the 64-bit program. To launch 64-bit program explicitly, use flag 0x4000. Note that other file functions also may be redirected; only run() can disable redirection itself.
2. Use special virtual folder Sysnative instead of System32. For example, run "$windows$\Sysnative\SnippingTool.exe". However this method has some limitations, eg cannot run administrative programs, such as regedit or msconfig.
3. Use the attached class. It can be used with any file functions. Note that with run() also need flag 0x30000.
4. Use a symbolic link. See next post.

Macro __Wow64DisableWow64FsRedirection help
Copy      Help
;On Windows 64-bit, there are 2 versions of system folder: system32 and SysWOW64.
;system32 contain 64-bit files. It is used by 64-bit applications.
;SysWOW64 contain 32-bit versions of these files. It is used by 32-bit applications, including QM.
;If a function in QM or other 32-bit application tries to access a file in system32 folder, Windows redirects it to the SysWOW64 folder. Normally 32-bit applications in function calls use system32, not SysWOW64; then the same code works on all Windows version.
;This behavior is the same with QM file functions (run, str.searchpath, etc) and Windows API functions.
;The 32-bit folder contains 32-bit versions of many of the system files. However not all.
;Use this class to temporarily disable this redirection, eg when you want to run a 64-bit system file.
;Call DisableRedirection when need redirection. Call Revert as soon as possible when already don't need disabling, because other functions may fail when redirection disabled.
;The class reverts automatically when the variable dies if Revert not called.
;Disables only in current thread.
;With run() use flag 0x30000, or may not work.
;The class does nothing on 32-bit Windows. Not error.
;Note: not all system folder subfolders/files are redirected. Some redirected differently.
;More info: google for "File System Redirector" or Wow64DisableWow64FsRedirection.

;You probably noticed that on Windows 64-bit also there are 2 program files folders. The "Program Files" folder contains 64-bit apps; the "Program Files (x86)" folder contains 32-bit apps.
;The redirection is not applied to program file folders. Don't need this class.
;In QM, special folder "$program files$" expands to the 32-bit folder ("Program Files (x86)"). QM is installed there. Environment variable "%ProgramW6432%" expands to the 64-bit folder ("Program Files").


#compile "____Wow64DisableWow64FsRedirection"
__Wow64DisableWow64FsRedirection x.DisableRedirection
run "c:\windows\system32\abcdefgh.exe" "" "" "" 0x30000

Attached Files
.qml   __Wow64DisableWow64FsRedirection.qml (Size: 2.93 KB / Downloads: 867)
Other way.

Create symbolic link to system32 somewhere, and run files through it. Then file system redirection is not applied.

This macro creates symbolic link system64 on desktop. QM must be admin.

Macro Macro1676
Copy      Help
CreateSymLink "$desktop$\system64" "$system$" 1

The function is somewhere in forum and archive.qml, and here it is again:
Function CreateSymLink
Copy      Help
function $symlink $target [flags] ;;flags: 1 folder

;Creates symbolic link.
;Error if fails.
;If symlink exists and is not folder, deletes.
;Symbolic links are supported on Vista and later.

dll- kernel32 !CreateSymbolicLinkW @*lpSymlinkFileName @*lpTargetFileName dwFlags
str s1.expandpath(symlink)
if(dir(symlink)) del symlink; err
str s2.expandpath(target)
if(!CreateSymbolicLinkW(@s1 @s2 flags)) end _s.dllerror

Copy      Help
run "$desktop$\system64\msconfig.exe"

You see folder path as "$desktop$\system64", but actually it is "c:\windows\system32".

Forum Jump:

Users browsing this thread: 1 Guest(s)