0

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

Shintaro Takechi
  • 1,215
  • 1
  • 17
  • 39
  • 1
    VS may be a 32 bit app. Consequently "C:\WINDOWS\System32" is getting redirected to "C:\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 Mar 21 '19 at 21:02
  • 1
    "C:\SysWOW64" above should be "C:\Windows\SysWOW64" – RGuggisberg Mar 21 '19 at 21:24
  • Ah that definitely solved the problem of accessing the batch file from visual studio. Thank you so much for the prompt reply! However, as the article you have linked has specified, Sysnative is only visible from 32bit program (VS in this case). I wonder how I can make both 32bit and 64bit program satisfied. – Shintaro Takechi Mar 21 '19 at 21:58
  • I decided to run 64 bit cmd.exe then run the batch file. – Shintaro Takechi Mar 21 '19 at 22:19

1 Answers1

0

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)

Shintaro Takechi
  • 1,215
  • 1
  • 17
  • 39