Java installation script fails in Windows as unsupervised user

I have a Powershell script that at some point runs a java process to install some files.
If I run it manually it works. The Java process opens a CMD window at some point showing progress and then I see the files installed on disk.
When I run the script with Packer the Java part fails for unknown reasons and the files are not installed.
I’ve tried to disable UAC with:

Write-Host "Disabling UAC..."
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force

but it didn’t help.
Any ideas?