Managing Unity version via CLI

Hi, I work at a University where we have Unity installed in our computer labs and I would like to use the headless CLI tool to manage what engine is installed with the right modules via a GPO script that runs on boot but I am having issues. It downloads the installation file fine but then when it comes to running it fails and gives “Error: No editor found for version 6000.3.18f1”. Running the script directly with administrative privileges works fine so I suspect it has something to do with the GPO running as the System user but it should have full privileges as far as I know.

This is the actual line that runs the install:
“C:\Program Files\Unity Hub\Unity Hub.exe” – --headless install --version 6000.3.18f1 --changeset 5ebeb53e4c07

I would start by looking at the Editor logs, or perhaps the Unity Hub logs if that is involved.

The system user acts as the “god” of the system, or “the system itself” as the name implies. It’s even more powerful than an Administrator account!

The distributed policy scripts would use it to do things without an active user needing to be logged in. This can be installing software, but that’s not guaranteed to work for every installer since they typically expect to be run by a user under a user account and aren’t necessarily tested (or designed to work) under these conditions. Unattended installs without a account sign in are more common to fail than to succeed.

The System user for instance has no “home” directory and thus the installer wouldn’t know where to write the AppData files. User-level registry keys may also be in the wrong location or non-existent. Even if the install succeeds it can thus still leave the installed application dysfunctional under a user account.

It’s best to run all application installs under a Administrator account and accept that it takes a bit longer for that account to first sign in on every machine.

Thank you both for you answers. I found the system users profile under C:\Windows\System32\Config\systemprofile which contains a Unity Hub folder under it’s Roaming AppData. I found two log files, info-log.json and install-log.json. I’ll attach the logs but the relevant lines seem to be

"install C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe /S /D=C:\Program Files\Unity\Hub\Editor\6000.3.18f1"
"An error occurred while installing C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe Error: Command failed: "C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe" /S /D=C:\Program Files\Unity\Hub\Editor\6000.3.18f1

    at genericNodeError (node:internal/errors:985:15)
    at wrappedFn (node:internal/errors:539:14)
    at ChildProcess.exithandler (node:child_process:417:12)
    at ChildProcess.emit (node:events:509:28)
    at maybeClose (node:internal/child_process:1124:16)
    at ChildProcess._handle.onexit (node:internal/child_process:306:5) {
  code: 2,
  killed: false,
  signal: null,
  cmd: '"C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Roaming\\UnityHub\\downloads\\UnitySetup64-6000.3.18f1.exe" /S /D=C:\\Program Files\\Unity\\Hub\\Editor\\6000.3.18f1',
  stdout: '',
  stderr: ''
}"
"An unknown error occurred while installing "C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe" Error: Command failed: "C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe" /S /D=C:\Program Files\Unity\Hub\Editor\6000.3.18f1

    at genericNodeError (node:internal/errors:985:15)
    at wrappedFn (node:internal/errors:539:14)
    at ChildProcess.exithandler (node:child_process:417:12)
    at ChildProcess.emit (node:events:509:28)
    at maybeClose (node:internal/child_process:1124:16)
    at ChildProcess._handle.onexit (node:internal/child_process:306:5) {
  code: 2,
  killed: false,
  signal: null,
  cmd: '"C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Roaming\\UnityHub\\downloads\\UnitySetup64-6000.3.18f1.exe" /S /D=C:\\Program Files\\Unity\\Hub\\Editor\\6000.3.18f1',
  stdout: '',
  stderr: ''
}"
"Error while installing an Editor INSTALL_ERROR: Error happened while executing the installer. Aborting.
    at execInstaller (file:///C:/Program%20Files/Unity%20Hub/resources/app.asar/build/main/unityInstallerProcess_win32-BOUWVP6O.js:296:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async installEditor (file:///C:/Program%20Files/Unity%20Hub/resources/app.asar/build/main/unityInstallerProcess_win32-BOUWVP6O.js:798:4)
    at async file:///C:/Program%20Files/Unity%20Hub/resources/app.asar/build/main/unityInstallerProcess_win32-BOUWVP6O.js:883:13 {
  code: 'INSTALL_ERROR',
  error: { code: 'INSTALL_ERROR', message: 'Error happened while executing the installer. Aborting.' },
  [cause]: Error: Command failed: "C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\UnityHub\downloads\UnitySetup64-6000.3.18f1.exe" /S /D=C:\Program Files\Unity\Hub\Editor\6000.3.18f1
  
      at genericNodeError (node:internal/errors:985:15)
      at wrappedFn (node:internal/errors:539:14)
      at ChildProcess.exithandler (node:child_process:417:12)
      at ChildProcess.emit (node:events:509:28)
      at maybeClose (node:internal/child_process:1124:16)
      at ChildProcess._handle.onexit (node:internal/child_process:306:5) {
    code: 2,
    killed: false,
    signal: null,
    cmd: '"C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Roaming\\UnityHub\\downloads\\UnitySetup64-6000.3.18f1.exe" /S /D=C:\\Program Files\\Unity\\Hub\\Editor\\6000.3.18f1',
    stdout: '',
    stderr: ''
  }
}"


Running it as task while logged in I can see the installation file showing up in the download folder referenced in the logs so it does manage to download it properly so it is seemingly failing when executing the actual installer. I could of course solve this by directly downloading the installation file instead and manually executing it but I would much prefer just using the Unity Hubs CLI.

unityhub-logs.zip (16.8 KB)

I managed to solve the issue, although it is not a clean solution.

I tried downloading the new Unity CLI tool to see if it would have the same issues and it did. However it did not delete the installer for the editor so I tried running it directly via a terminal and it gave me “NSIS Error: Error launching installer” but if I copied to my desktop it runs with out any issues so it is specifically an issue with launching the installer from inside the Systems user profile that is the issue.

SOLUTION:

My fix was for my batch file to temporarily set the System users AppData to be inside C:\Windows\temp and from there it can execute that installer without any issues. In theory you can probably redirect AppData to be wherever you want as long as you can run the installer from there but I choose temp.

I only got this to work with the new Unity CLI tool and not the Unity Hub CLI tool, I suspect due to them referencing AppData differently.

I don’t know if the CLI tool itself could detect when it is running as the system user and do this on it’s own but this at least solved it for me.

Could you provide some detail (or your batch file) as to how you got this to work? I’ve tried a few strategies with the 6000.3.19f1 installer and modules without success.

I’m out of town this weekend but I can post the batch script Monday or Tuesday.

This is the entire batch script, the relevant part is the set APPDATA=C:\Windows\Temp\Unity, it will within the context of the batch script change the SYSTEM users appdata to a place where it can actually run the installer. I choose to point it to C:\windows\temp but in theory you can point it to wherever you want.

@echo off
set LOGFILE="C:\logs\unity_editor.log"
call :UNITY > %LOGFILE%
exit /B

:UNITY

set UNITY_VER=6000.3.18f1
set CHANGESET=5ebeb53e4c07
set APPDATA=C:\Windows\Temp\Unity

echo "Trying to install Editor %UNITY_VER% if missing with modules"

unity --non-interactive --no-banner --verbose install %UNITY_VER% --changeset %CHANGESET% 

unity --non-interactive --no-banner --verbose install-modules --editor-version %UNITY_VER% --module ios android android-sdk-ndk-tools windows-il2cpp webgl --accept-eula

rd /s /q %APPDATA%

echo "Done"

Great, thank you, I will give this a try!