[wix-users] Hand over an action to wix bundle elevated process

Gerhard Matzen gmatzen at osisoft.com
Thu May 4 13:06:50 PDT 2017


When not elevated, we simply just restart elevated and then quit.  There are a few edge cases to consider to find the original source in all cases.

      /// <summary>
      /// RestartElevatedAndQuit() will restart the bundle elevated and then quit. 
      /// The original command line is preserved with the exception of parameters beginning with "-burn.".
      /// Depending how the bundle was started, RestartElevatedAndQuit() will either restart the bundle from 
      /// WixBundleSourceProcessFolder or from Process.GetCurrentProcess().MainModule.FileName.
      /// For example, the former directory is used when a user simply double clicks on a bundle and the latter
      /// directory is used when the bundle is started from Programs and Features.
      /// </summary>
      /// <param name="prompt">If true is passed (recommended), the user will be given a chance to exit setup without elevating.</param>
      public void RestartElevatedAndQuit(bool prompt)
      {
         if (prompt)
         {
            var message =
               $"The \"{Bundle.GetBundle().DisplayName}\" setup kit requires elevated permissions.{Environment.NewLine}{Environment.NewLine}Restart now with elevated credentials?";
            var result = ShowMessageDialog(message, MessageBoxButton.OKCancel, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Cancel)
            {
               LogInfo("User has chosen to cancel setup without restarting with elevated permissions.");
               throw new RestartElevatedException();
            }
         }
         var environmentArgs = Environment.GetCommandLineArgs();
         var args = string.Join(" ", environmentArgs.Select(
            arg => arg.StartsWith("-burn.", StringComparison.InvariantCultureIgnoreCase) || arg == environmentArgs[0]
               ? string.Empty
               : arg.Any(char.IsWhiteSpace)
                    ? $"\"{arg}\""
                    : arg));

         string fileName, workingDirectory;
         if (TryGetWixBundleSourceProcessPath(out fileName))
         {
            LogInfo($"{nameof(Bundle.Variables.WixBundleSourceProcessFolder)} is defined.");
            workingDirectory = Bundle.Variables.WixBundleSourceProcessFolder;
         }
         else
         {
            LogInfo($"{nameof(Bundle.Variables.WixBundleSourceProcessFolder)} is not defined defined. Determining source from current process.");
            fileName = Process.GetCurrentProcess().MainModule.FileName;
            workingDirectory = Environment.CurrentDirectory;
         }
         LogInfo($"File: {fileName}. Working directory: {workingDirectory}.");

         var startInfo = new ProcessStartInfo
         {
            UseShellExecute = true,
            FileName = fileName,
            WorkingDirectory = workingDirectory,
            Verb = "runas",
            Arguments = args
         };
         try
         {
            Process.Start(startInfo);
         }
         catch (Win32Exception ex)
         {
            //1223 == "The operation was canceled by the user."
            //The cancel error occurs if the user says no to the UAC prompt.  
            if (ex.NativeErrorCode != 1223)
            {
               throw;
            }
         }
         throw new RestartElevatedException();
      }

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Hoover, Jacob
Sent: Thursday, May 4, 2017 12:59 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Hand over an action to wix bundle elevated process

I would assume that means your BA elevates twice.  Once from your Daemon during Detect, and once when the user hits install? 

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of John Cooper
Sent: Thursday, May 04, 2017 2:33 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Hand over an action to wix bundle elevated process

To elevate during Detect, I wrote a daemon process specifically for interrogating IIS communicating with the main bundle via net.pipe and serializing the data using JSON.  Works pretty well while UAC is enabled or the installing user is a true Administrator.  Can get iffy in other scenarios.

--
John Merryweather Cooper
Senior Software Engineer -- Integration Development Group -- Enterprise Notification Service Jack Henry & Associates, Inc.® | Lenexa, KS  66214 | Office:  913-341-3434x431050 JoCooper at jackhenry.com




-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Hoover, Jacob
Sent: Thursday, May 4, 2017 2:24 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] Hand over an action to wix bundle elevated process

The e-mail below is from an external source.  Please do not open attachments or click links from an unknown or suspicious origin.

The problem is that the BA doesn't elevate until Apply is called. And apply just executes the plan.

What you really are asking for is an ability to elevate during detect, in order to make better decisions during plan. This may be a worth wile feature, but the BA currently doesn't support this from my recollection.

P.S. This is really a fault of IIS where it doesn't allow read access to the configuration from a non-elevated user.

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Ireneusz Grala
Sent: Thursday, May 04, 2017 1:24 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: [wix-users] Hand over an action to wix bundle elevated process

Hello, to everyone!

I know that during installation burn engine creates UI-less process with elevated priviliges. I also know it can be created earlier by calling Engine.Elevate method. Is there a way to communicate with this process and invoke an action that requires elevated user rights? I would like to discover in bootstrapper what is the current website configuration in IIS.

The whole thing is about updating my version one app but preserving any changes that customer could make to website binding.

Hope this is clear enough.

Thanks for any advice.

--
Z poważaniem / Best regards

Ireneusz Grala

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/
NOTICE: This electronic mail message and any files transmitted with it are intended exclusively for the individual or entity to which it is addressed. The message, together with any attachment, may contain confidential and/or privileged information.
Any unauthorized review, use, printing, saving, copying, disclosure or distribution is strictly prohibited. If you have received this message in error, please immediately advise the sender by reply email and delete all copies.

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/


More information about the wix-users mailing list