Forum Discussion
marcdaniel
Aug 21, 2024Copper Contributor
Deploying Win32 App and using Env. Variables
Hi,
We are trying to deploy an application as a Win32 app, the script to install (a .cmd) references the env. variable for the Program Files folder - %programfiles% - however when this runs, we get the error that the agent cannot be installed in the C:\Program Files (x86), this is expected behaviour for the agent as it must be installed in C:\Program Files.
The variable 'echoes' out as expected on the PC, so why when installing via Intune does it resolve to the x86 path?
- NickECopper ContributorWhen doing scripting in win32 apps you need to switch the context of powershell for it to work as expected. This happens for things like this and writing to the correct registry locations. Try this at the start of your script.
# If we are running as a 32-bit process on an x64 system, re-launch as a 64-bit process
if ("$env:PROCESSOR_ARCHITEW6432" -ne "ARM64"){
if (Test-Path "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe")
{
& "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy bypass -NoProfile -File "$PSCommandPath"
Exit $lastexitcode
}
}