-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Per User" installer, AfterInstall is not elevated. #1567
Comments
Hello Oleg, I will take a look at this sample and will consult next week with my team if this could be an acceptable solution. Thanks for creating this library and answering everyone's questions. |
I am optimistic about that. The most difficult part of this work is serialization of a session object that can be transferred to another (elevated) process context. The biggest problem with that that WiX team has designed the Session in such a way that it can have no abstraction whatsoever. You cannot instantiate it. If you manage to bypass this, the object must have a live connection to the unmanaged session object, which is 100% incompatible with serialization and external process context. But I just solved this problem yesterday. So we are on the projection of making it happen. |
That's good news! |
I think so |
, #1567). Not integrated to the API yet
Yes it will be. See this post |
Hi Oleg, in the meantime, I've been testing the "RestartElevated" solution, I've copied from your sample. I found that this was working ok when I install, but it didn't work when uninstalling from "Add/Remove programs", the UIInitalized event is not fired when uninstalling. But I've noticed that the BeforeInstallEvent is fired during uninstall, so I've done a workaround to overcome this issue, here is my code, in case you want to update your sample. project.BeforeInstall += ( SetupEventArgs e ) =>
{
if ( e.IsUninstalling && !e.IsElevated )
{
e.Result = ActionResult.Failure;
var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.FileName = "msiexec.exe";
startInfo.Arguments = $"/x \"{e.MsiFile}\"";
startInfo.Verb = "runas";
Process.Start( startInfo );
}
};
project.UIInitialized += ( SetupEventArgs e ) =>
{
if ( e.IsInstalling && !e.IsElevated )
{
e.Result = ActionResult.Failure;
var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.FileName = "msiexec.exe";
startInfo.Arguments = $"/i \"{e.MsiFile}\"";
startInfo.Verb = "runas";
Process.Start( startInfo );
}
}; |
- The whole round trip implementation for the elevated events (#1565, #1567). Not integrated to the API yet - added `restart elevated` routine for custom BA sample - Issue #1554: Add custom Wizard-like Installer to Bundle / Burn Installer - Implemented `MsiExePackage`. Triggered by #1554 Dedicates sample `WixBootstrapper_MsiEmbeddedUI` shows how to use it ```C# var bootstrapper = new Bundle("Managed Product Bundle", new MsiExePackage(msi) { Name = "ManagedProduct", }); ``` - Issue #1557: Error when specifying Package Platform as ARM64 - WiX4: added `WixProject.WixBuildCommandGenerated` even. Triggered by #1557 - Added `CommonTasks.MapAsDeferredProperty` extension method: ```C# project.MapAsDeferredProperty("MYPROPERTY"); // instead of project.DefaultDeferredProperties += ",MYPROPERTY"; ``` - Added `string.CompleSelfHostedMsi` extension for building self executable msi files: ```C# msi.CompleSelfHostedMsi(msi + ".exe"); ``` - added calling `dotnet tool restore` when using wix as a local tool. Triggered by #1546
Done. The latest release v2.2.0 allows controlling the hosting environment of the managed events (custom actions). project.BeforeInstallEventExecution = EventExecution.MsiSessionScopeImmediate;
project.BeforeInstallEventExecution = EventExecution.MsiSessionScopeDeferred;
project.BeforeInstallEventExecution = EventExecution.ExternalElevatedProcess;
// the same for Load and AfterInstall events This is the code sample in the repository: https://github.com/oleg-shilo/wixsharp/blob/wix-v4-master/Source/src/WixSharp.Samples/Wix%23%20Samples/InstallEventElevation/setup.cs |
Thank you very much Oleg, much appreciated. I've upgraded the nuget package to 2.2.0 and tested it but when it compiles the msi an error is shown: I've looked at the packages\WixSharp_wix4.bin.2.2.0\lib folder and I don't see this exe file, maybe you forgot to add it to the nuget package? |
Oh my, Sorry. |
Done. Please update the package. It was a packaging problem that is now addressed by publishing a new package version for the already released binaries. NuGet package v2.2.1 contains WixSharp v2.2.0 binaries. |
Now it compiles the msi ok, however in my tests the installation has failed, it seems that if you use the session object in the custom actions it throws an exception: Calling custom action WixSharp!WixSharp.ManagedProjectActions.WixSharp_AfterInstall_Action
WixSharp aborted the session because of the error:
System.Exception: WixToolset.Dtf.WindowsInstaller.InstallerException: Se produjo una excepción de tipo 'WixToolset.Dtf.WindowsInstaller.InstallerException'.
en WixToolset.Dtf.WindowsInstaller.Session.Message(InstallMessage messageType, Record record) en <hidden content>
en WixToolset.Dtf.WindowsInstaller.Session.Log(String msg) en <hidden content>
en WixSharp.ManagedProject.InvokeClientHandlersInternally(Session session, String eventName, IShellView UIShell)
en MsiEventHost.Program.Main(String args)
en WixSharp.ManagedProject.InvokeClientHandlersExternally(Session session, String eventName)
CustomAction WixSharp_AfterInstall_Action returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) I've tried removing the calls to the session.Log inside my custom action but it also fails, I use the sesion object also to retrieve the INSTALLDIR from CustomActionData or directly from session object. |
All elevated CAs, regardless of whether either via an external event host or by making it deferred, are executed outside of MSI session. Thus session object is always disconnected. Thus if you try to access session attributes will always throw an exception. Note, this is MSI/WiX limitation and it's not connected any WixSharp functionality. Though WixSharp goes the extra mile and preserves some of the session properties for accessing from deferred CA. Thus you can access the properties by using an alternative syntax (extension method): var test = session.Property("TEST_PROPERTY"); You can easily check what properties are available for your action by displaying them all from the elevated event: project.AfterInstall += msi_AfterInstall;
...
static void msi_AfterInstall(SetupEventArgs e)
{
MessageBox.Show(e.ToString(), "AfterExecute");
} |
I have added an extra wiki section to describe the new event execution model: |
Hi Oleg,
we are moving our old installer project created from a visual studio vdproj to WixSharp.
I run into a problem, the old installer was installing "perUser" and required elevation to execute some custom actions in a .net assembly, and this was working fine, the custom actions executed elevated.
I have created a new ManagedProject, Scope= "perUser" and in the AfterInstall event I do the necessary actions, but I run into the problem that this execution is not elevated ( e.IsElevated == false ).
If I set"perMachine" then the AfterInstall is elevated ( e.IsElevated == true )
Is there any way in a "perUser" installer to run custom actions elevated?
I need it to be "perUser" so that the new msi it generates will do the upgrade of old installs well.
I have tried with ManagedCustomAction but also the same thing happens, they run without elevation when it is "perUser".
The text was updated successfully, but these errors were encountered: