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

Vista

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

File System Redirection


Question:

On Windows Server there is a file %WINDIR%\SYSTEM32\ProdSpec.ini which tells you what edition of the OS is installed. I was using this for years now to determine if a server is standard or advanced and so on.

Doing my first steps on Windows 2003 Standard SP2 x64 I found the following line failing with an error opening file error:

strProdSpecIni = FileGet ('C:\Windows\System32\ProdSpec.ini')
The file exists and I can open and modify it in Notepad but FileGet or IniReadPvt fail to open the file. I'm logged on as the local Administrator to this server that is running W03 Standard R2 SP2 x64.

When I do a FileItemize ('C:\windows\system32\*.ini') I get 1 file returned, when I do a DIR C:\windows\System32\*.ini in a command prompt I get 19 files. I used IntControl (5,1,0,0) to include system/hidden files (although none of the ini files is marked as system r hidden), no difference.

When I do a cmd /k dir c:\windows\system32\*.ini from Start/Run I get 19 files listed, when I do a RunWait ('cmd','/k dir c:\windows\system32\*.ini') from within Winbatch Studio I get only 1 file?!?

Answer:

Use IntControl 92
oldvalue = IntControl( 92, "disable", 0, 0, 0 )
strProdSpecIni = FileGet ('C:\Windows\System32\ProdSpec.ini')
IntControl( 92, "revert", oldvalue, 0, 0 )
Vaguely similiar to the RegOpenFlags function where you can control whether or not you are dealing wiht the 32 or 64 bit view of the registry.... (Registry Redirection)

You now have IntControl 92 to help you deal with "File System Redirection" where, when accessing some system folders, your code is defaulted to view a 32-bit view of the folder. If you wish to view the 64 bit view of the volder, you mush TEMPORARILY disable the File System Redirection.

It is IMPORTANT to minimize the code run whn the File System Redirection is disabled, especially when loating extenders, instanciating or using COM object, or doing anything that asks Windows to loads any new DLLs or anything. The problem is that wile 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, GP Fault, or otherwise not function properly.

I have only seen File Redirection problems when trying to access the Windows and Windows\System folders.

User Reply:

IntControl 92 did the trick. I know you guys are working on several improvements, what about adding a parameter to certain functions that would allow to specify which view to get. Something like:
FileGet ('C:\Windows\System32\ProdSpec.ini','x86') or 
RegQueryValue (@REGMACHINE,'somekey','[somevalue]','x86')
to get the 32bit view on a 64bit system. That would be one line instead of 3 and would also make sure that redirection is not disabled longer than necessary.

Answer:

Perhaps an interim workaround?
#DefineFunction MyFileGet(fn,nullcharflag,redirectflag)
   WOW32ON64= -7
   if WinMetrics(WOW32ON64) == 2
       if redirectflag="x86"
          oldvalue = IntControl( 92, "disable", 0, 0, 0 )
          revalue=FileGet (fn, nullcharflag)
          IntControl( 92, "revert", oldvalue, 0, 0 )
       endif
   else
          retvalue=FileGet (fn, nullcharflag)
   endif
   return retvalue
#EndFunction

stuff = MyFileGet ('C:\Windows\System32\ProdSpec.ini', "", "x86")

Article ID:   W17485
File Created: 2008:04:10:15:11:30
Last Updated: 2008:04:10:15:11:30