Even though the ConfigMgr 2012 client is supposedly 64bit now, the issue with 64bit file system redirection is still very much a problem during Task Sequence and even regular package/program deployments when we want to copy things to the ‘Native’ “%Program Files%” or “%WinDir%System32″.  File System redirection kicks in and we are magically transported to the 32bit “Program Files (x86)” or “WindowsSysWOW64″. Boo hiss.  I even found a log entry in the client-side execmgr.log which clearly states;

Running "C:Windowsccmcache3CopyFiles-Temp.cmd" with 32bitLauncher

Why? Why? Why?

In the Task Sequence we can easily get around this problem by choosing to run a “Run Command Line” step instead of an Install Package step; we reference our package and command line and ensure we tick the box to “Disable 64bit file system redirection.”  This is all well and good but what about deployments outside of the Task Sequence?  There simply isn’t the same option, so we need to build this into our script/batch file that we are trying to run.  My borderline Obsessive Compulsiveness dictates that the single solution must ‘just work’ for both 32bit and 64bit operating systems.

The most elegant way I have found for doing this that doesn’t involve re-writing sections of your batch file to cater for the various operating environments, involves taking advantage of being able to invoke the ‘Native’ 64bit command processor (system32cmd.exe) from within any 32bit command processor running within a 64bit OS if needed.  Here’s a snippet of code you simply add to the very top of your existing batch files…

IF "%PROCESSOR_ARCHITEW6432%"=="" GOTO native
  %SystemRoot%Sysnativecmd.exe /c %0 %* Exit
:native
<your script starts here>

What this will do for you, is first detect if the batch file is being ran from within a 32bit command interpreter on a 64bit OS – if it isn’t then the code jumps to the “:native” label and continues your script as usual.  If we are in a 32bit command interpreter on a 64bit OS, then the second line invokes the ’Native’ 64bit command processor and re-launches this very same batch file.  The condition at the top will simply be evaluated again by the 64bit command processor and ignored (as we are running 64bit cmd.exe in 64bit OS) and your script will happily continue without being subject to redirection.  Neat!