Mars
Mars

Reputation: 2572

System32\xyz folder not found when running batch during VS build event

When running a batch as a post-build event from VS, some of my folders become invisible to the command line. The error log and output logs are nondescript.

In my subsequent batch, I cannot access SCP (System32\OpenSSH\scp.exe)

Build event:

IF NOT DEFINED PUBLISHING (
set PUBLISHING ='ON'
call "$(ProjectDir)Publish.bat"
PUBLISHING=
)

Changing call to start, a cmd window pops up and I have checked my variables and poked around in the environment.

When poking around, if I try to change directories, it claims that System32\OpenSSH doesn't exist!
(Absolute path truncated)

What can System folders to not be accessible to an admin?

Upvotes: 0

Views: 99

Answers (1)

Mars
Mars

Reputation: 2572

Based on Mofi's comment,

Please read the Microsoft documentation about WOW64 Implementation Details. There are two %SystemRoot%\System32 directories. Which one is used depends on execution environment, 32 or 64 bit environment.

it was easy to determine that the cmd being used by VS was x86 and thus does not have access to the same System32 folder. In order to use OpenSSH\SCP, I needed to call the the x64 version of cmd.

For that, we can also refer to Mofi's other answer.

The result is something like this:
Note: Here we start a new cmd window because publish needs user input. A regular "call" should be fine too

IF NOT DEFINED PUBLISHING (
set PUBLISHING='ON'
:: We know we are currently running x86, so call other cmd without checking version
start %SystemRoot%\Sysnative\cmd.exe /C call "$(ProjectDir)Publish.bat" 
PUBLISHING=
::Needed to add for build to 'succeed', not in original script post
exit /b 0 
)

Upvotes: 1

Related Questions