Search code examples
visual-studiobatch-filebuildpackageiso

Why is oscdimg.exe, Under Visual Studio, not recognized as an internal or external command, operable program or batch file


On Visual Studio (2015 and 2017) I have a batch file that I run on AfterBuild.

  <Target Name="AfterBuild">  
    <Exec Command="&quot;$(ProjectDir)\test.bat&quot;" WorkingDirectory="$(ProjectDir)" />
  </Target>

Inside the batch file it is quite simple line

"%SYSTEMROOT%\System32\oscdimg.exe" -n -m "%~dp0.\bin" -l"testdisk" "%~dp0\test.iso"

When I run the batch file by itself (simple double click on bat file), it functions as desired.

However, when Visual Studio get to AfterBuild, following error shows up.

'"C:\WINDOWS\System32\oscdimg.exe"' is not recognized as an internal or external command, operable program or batch file.

Would anybody have clue as to why this is occuring? Is there restriction on visual studio AfterBuild? Even if I take the extra double quotation around oscdimg.exe (because there are no white spaces) the error does not go away.

Any help would be appreciated.

Thank you


Solution

  • Thanks to RGuggisberg with his comment I was able to find the cause of this issue. Let me quote him

    VS may be a 32 bit app. Consequently "C:\WINDOWS\System32" is getting redirected to "C:\Windows\SysWOW64" and oscdimg.exe probably is not there. Try using this: "C:\Windows\Sysnative\oscdimg.exe" See www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm – RGuggisberg

    So I have decided to run 64 bit version of the command prompt from VS AfterBuild.

      <Target Name="AfterBuild"> 
        <Exec Command="%windir%\sysnative\cmd.exe /c &quot;$(ProjectDir)\test.bat&quot;" WorkingDirectory="$(ProjectDir)" />
      </Target>
    

    I have done so in order to avoid changing the batch file which has chance of running by itself (meaning running from 64 bit explorer)