Closed Harakku closed 4 years ago
We use System.Diagnostics.Process
mainly because of log output for -Verb RunAs
.
Do you have more examples for this early exit?
I tried but didn't manage to make a simplified version of the bug and I've only seen it happen with this one uninstaller.
I wanted to see if logging would reveal something so I replaced the "-RunAs" with "-Log C:\log.txt" and ran powershell as admin. I ran install/uninstall over ten times and there were no errors. Interesting.jpg. Then I removed the -Log parameter and there were errors again. It seems that -Log is adding a little bit of delay at the end of the function which makes everything run smoothly.
At first, I was pretty sure that the inherent problem wouldn't be in the uninstaller because Start-Process was managing it just fine. Now I am not sure if the reason for the success of Start-Process is just possibly more delay at the end.
Since I'm not sure if I should point finger to the uninstaller or Scoop, I'll close this for now and come back if more info is revealed.
Sometimes Invoke-ExternalCommand returns too early which can cause errors if Scoop tries to remove an installation directory while an uninstaller is still running.
During my testing, Scoop ended up throwing an error about 50% of the times. I was testing this manifest and here's the uninstaller script I used:
"script": "Invoke-ExternalCommand \"$dir\\Riot Games\\League of Legends\\Uninstall League of Legends.exe\" -ArgumentList \"--mode unattended\" -RunAs"
On the other hand, Start-Process returns every time precisely when an uninstaller closes, at least based on my testing. That is noteworthy since both commands seem to have been implemented using the same System.Diagnostics.Process class. The script I used:
"script": "Start-Process \"$dir\\Riot Games\\League of Legends\\Uninstall League of Legends.exe\" -ArgumentList \"--mode unattended\" -Verb RunAs -Wait"
I tried both system-installed Powershell 5 and pre-release of Powershell 7. I also tried to run the commands from both an administrator shell and a user shell with a UAC popup. There was no difference. The problem also exists when taking only the Invoke-ExternalCommand function to a new file and running it separated from Scoop.
I have no idea why the Scoop function and Start-Process work differently but one solution could be to rework the Scoop function into using Start-Process behind the scenes instead of System.Diagnostics.Process class directly.