Share via

Intune ignores command in Batch script when installing a Win32 App

Bühler Gabriel 81 Reputation points
2026-04-20T12:25:46.8366667+00:00

Hello Everyone

setx RLM_LICENSE "******@SERVERNAME.NETWORK.NET" /M
Start-Process -FilePath "Converge5.11.exe" -ArgumentList "/S" -Wait

Im trying to set up a simple installation script that installs an application (Converge) and then it should also set up an Environment variable for a License server:

The issue is that Intune just skips the Environment command (or it doesn't work properly because I have to run it in System Context). The command does work when I add it manually after the fact over the terminal. Is there any way to circumvent this issue? I also tried it with Powershell, but it doesn't even work manually with powershell,I tried this script here:

Start-Transcript -Path "C:\Windows\Temp\converge_install.log" -Append
# Set in current process so installer can use it
$env:RLM_LICENSE = "2765@SERVERNAME.NETWORK"
Write-Host "RLM_LICENSE in process: '$env:RLM_LICENSE'"
Start-Sleep -Seconds 2
# Run installer
Write-Host "Starting Converge5.11.exe installer..."
Start-Process -FilePath "Converge5.11.exe" -ArgumentList "/S" -Wait
Write-Host "Installer exited"
# NOW set variable via CMD using setx (machine-level)
Write-Host "Setting RLM_LICENSE via CMD (setx)..."
Start-Process -FilePath "cmd.exe" -ArgumentList "/c setx ******@SERVER.NET /M" -Wait -NoNewWindow
# Optional: verify from registry again
$check = [Environment]::GetEnvironmentVariable("RLM_LICENSE", "Machine")
Write-Host "RLM_LICENSE in registry after CMD setx: '$check'"
Stop-Transcript

Thank you for your help.

Kind regards,

Gabriel

Microsoft Security | Intune | Application management
0 comments No comments

2 answers

Sort by: Most helpful
  1. Pavel yannara Mirochnitchenko 13,451 Reputation points MVP
    2026-04-28T10:54:22.9133333+00:00

    Sense you've mentioned System Context, for manual test execution of the script, you should run the script with System Context as well, not local admin. So I suggest use the psexec.exe or psexec64 to emulate real system context enviroment on your test machine for script testing. You are also logging the script already which is good, so some answers might be found in log file already.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-04-20T12:26:08.9+00:00

    Intune doesn’t “skip” the command – environment variables set at runtime are process‑scoped unless explicitly written to the machine or user store, and context (System vs User) also matters.

    Key points from the Intune side:

    • For a Win32 app, Intune runs the installer (and any script you wrap it with) in the context you configure under Install behavior (System or User). The script runs in that same context, and Intune only cares about the installer’s exit code for success/failure.
    • If the installer needs the variable during setup, it must exist in that same process (or parent process) at install time.
    • If the goal is to persist the variable for later use, it must be written to the machine or user environment (registry) from the same context that will later read it.

    To make this reliable with Intune Win32 apps:

    1. Package the installer and a PowerShell script as a Win32 app using the Microsoft Win32 Content Prep Tool (.intunewin).
    2. Configure the Win32 app Install command to call PowerShell in 64‑bit if needed, for example:
         %SystemRoot%\Sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File .\Install-Converge.ps1
      
      This avoids the default 32‑bit powershell.exe behavior mentioned in the Intune Win32 app program settings.
    3. In Install-Converge.ps1, do both:
      • Set the variable in the current process so the installer can see it.
      • Persist it at machine level so it is available after installation.
      Example:
         Start-Transcript -Path 'C:\Windows\Temp\converge_install.log' -Append
         
         # 1. Make variable visible to installer process
         $env:RLM_LICENSE = '2765@SERVERNAME.NETWORK'
         
         # 2. Persist at machine level (System context)
         [Environment]::SetEnvironmentVariable('RLM_LICENSE', '2765@SERVERNAME.NETWORK', 'Machine')
         
         # 3. Run installer from same process/context
         Start-Process -FilePath '.\Converge5.11.exe' -ArgumentList '/S' -Wait
         
         # 4. Verify from registry view
         $check = [Environment]::GetEnvironmentVariable('RLM_LICENSE', 'Machine')
         Write-Host "RLM_LICENSE in registry after set: '$check'"
         
         Stop-Transcript
      
    4. In the Win32 app properties in Intune:
      • Set Install behavior to System if the app and variable must be machine‑wide.
      • Ensure the detection rule is based on the app (file/registry) and not on the environment variable.

    If using a batch file instead of PowerShell, call setx with the correct syntax and ensure the batch file is the actual Install command for the Win32 app so it runs in the same context as the installer. Remember that setx writes to the registry and does not affect the current process environment; the installer will not see the new value unless it is started after setx from a new process.

    For more complex logic (prerequisite checks, post‑install configuration), using a PowerShell script as the installer wrapper is recommended and fully supported by Intune.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.