WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

64-bit

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

File Redirection

 Keywords:  IntControl 92 Sysnative File Redirection

File Redirection

When 32 bitWinBatch it is run a 64 bit Windows platform the Windows file system auto-magically redirects file operations that refer to 64 bit directories to the 32 bit equivalents. For example, the %windir%\System32 directory is reserved for 64-bit applications. Since most System DLL file names were not changed when porting to 64-bit, 32-bit applications must use a different directory as their System32 directory. WOW64 hides this difference using file system redirection. Whenever a 32-bit application,like WinBatch, attempts to access %windir%\System32, the access is redirected to a new directory, %windir%\SysWOW64. IntControl 92 can be used to disable this functionality.

Disabling file system redirection affects all file operations performed by the the script, so it should be disabled only when necessary for a single call and re-enabled again immediately after the function returns. Disabling file system redirection for longer periods can prevent WinBatch from loading system DLLs, causing the it to fail.

NOTE: It is REALLY important to minimize the code run when the File System Redirection is disabled, especially when loading WIL Extenders, using COM / OLE, or doing anything that asks Windows to load any new DLLs. The problem is that while File System Redirection is disabled, your code will be looking at the wrong version of windows and will attempt to load wrong (64 instead of 32 bit) versions of modules, and usually fail, GPF, or otherwise not function properly.

32-bit applications can also access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.

Details: http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx

IntControl 92
Disables or reverts file system redirection when running in WOW64 (32-bit emulation under 64-bit Windows). Complete example:
AddExtender("WWWNT34I.DLL")

sPath  = 'c:\Windows\System32\Test'

; Disable redirect
oldvalue = IntControl( 92, "disable", 0, 0, 0 )

;Delete and recreate directory
if DirExist(sPath) then DirRemove(sPath)
DirMake(sPath)

;Add permissions
wntAccessAdd("", sPath, "Users", 300, "Dir:Change") 
Pause(sPath,"Successfully applied permissions")

; Remove test directory
DirRemove(sPath)
Pause(sPath,"Successfully removed directoy")

; Enable redirect
IntControl( 92, "revert", oldvalue, 0, 0 )
Sysnative

Instead of using IntControl 92, use 'Sysnative' where you mean 'system32' in the file paths and all is well i.e.,

sPath = 'c:\Windows\Sysnative\Test'

Complete example:

AddExtender("WWWNT34I.DLL")
sPath  = 'c:\Windows\Sysnative\Test'  ; Notice the use of Sysnative

;Delete and recreate directory
if DirExist(sPath) then DirRemove(sPath)
DirMake(sPath)

;Add permissions
wntAccessAdd("", sPath, "Users", 300, "Dir:Change") 
Pause(sPath,"Successfully applied permissions")

; Remove test directory
DirRemove(sPath)
Pause(sPath,"Successfully removed test directoy")


Article ID:   W17645
Filename:   File Redirection.txt
File Created: 2012:10:18:08:34:20
Last Updated: 2012:10:18:08:34:20