clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
426 stars 39 forks source link

Update.exe fails to start app requiring elevation #146

Closed lars-29palms closed 1 year ago

lars-29palms commented 1 year ago

First of all thank you for keeping this project alive!

We have just migrated our app to .NET 6 and moved from Squirrel.Windows to this package, everything working flawlessly so far except for the Update.exe failing to launch the app after installation. Due to the nature of the app, it requires elevated permissions. Squirrel.Windows didn't have a problem with this, but much has changed with Clowd.Squirrel I suppose!

For now we could go back to Squirrel.Windows and live with depending on .NET Framework but it would be great to switch to this fully native, well maintained project.

Here is the error log:

2023-02-11 21:49:36.5507 [ERROR] - IEnableLogger: Failed to invoke post-install: System.ComponentModel.Win32Exception (740): An error occurred trying to start process 'C:\Users\lars2\AppData\Local\Test\app-2.1.0-rc1\Test.exe' with working directory 'C:\Users\lars2\AppData\Local\Test\app-2.1.0-rc1'. The requested operation requires elevation.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo )
   at System.Diagnostics.Process.StartCore(ProcessStartInfo )
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo )
   at Squirrel.UpdateManager.ApplyReleasesImpl.<>c.<invokePostInstall>b__10_6(ProcessStartInfo info) in ./UpdateManager.ApplyReleases.cs:line 436
   at Squirrel.EnumerableExtensions.ForEach[TSource](IEnumerable`1 source, Action`1 onNext) in ./Internal/EnumerableExtensions.cs:line 59
   at Squirrel.UpdateManager.ApplyReleasesImpl.invokePostInstall(SemanticVersion currentVersion, Boolean isInitialInstall, Boolean firstRunOnly, Boolean silentInstall) in ./UpdateManager.ApplyReleases.cs:line 434
   at Squirrel.Utility.LogIfThrows(IFullLogger This, LogLevel level, String message, Func`1 block) in ./Internal/Utility.cs:line 634
2023-02-11 21:49:36.5659 [FATAL] - Program: Encountered fatal unhandled exception.: System.AggregateException: One or more errors occurred. (An error occurred trying to start process 'C:\Users\lars2\AppData\Local\Test\app-2.1.0-rc1\Test.exe' with working directory 'C:\Users\lars2\AppData\Local\Test\app-2.1.0-rc1'. The requested operation requires elevation.)
caesay commented 1 year ago

Squirrel does not technically support any apps which require elevation. This is true of the original and this fork. In your case, you've probably specified that your app requires elevation in your manifest. If Squirrel were to launch your app, the user would get the UAC dialog at least twice during installation, and that's not ideal / part of Squirrel's intended use.

I suspect the reason this is throwing instead of raising the UAC dialog is because of the move to .net 6.0, which turned off Process.Start ShellExecute by default, therefore it can not be elevated. I don't intend to fix this or support elevated apps at the moment.

My suggestion would be for your main program (the one that is Squirrel aware) to be a standard non-elevated binary. It can launch the exe which requires elevation after the Squirrel hooks are complete (eg. SquirrelAwareApp.HandleEvents)

lars-29palms commented 1 year ago

Thanks for your feedback @caesay ! I understand the reasoning behind this, which is one of the main ideas behind Squirrel - next to no user interaction. I will implement the launcher app eventually, which then launches the main app elevated. Requires some rework but certainly possible.