-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7ad81ca
commit 90111a5
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Source/src/WixSharp.Samples/Wix# Samples/RestartElevated(UI)/Build.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
..\..\cscs.exe setup.cs | ||
pause |
4 changes: 4 additions & 0 deletions
4
Source/src/WixSharp.Samples/Wix# Samples/RestartElevated(UI)/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This sample demonstrates how to ensure that setup runs elevated UI. | ||
Normally MSI elevates the actual installation stage (InstallSequence) while leaving the UI interaction (InstallUISequence) unelevated. This sample shows how to elevate the whole round trip. | ||
Note: the ManagedUI gives you the best user experience as native UI does not allow full control over dialogs (the initial setup exit dialog needs to be closed manually). | ||
Execute corresponding .cmd file to build desired msi. Then execute the .msi to start the installation. |
51 changes: 51 additions & 0 deletions
51
Source/src/WixSharp.Samples/Wix# Samples/RestartElevated(UI)/setup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//css_dir ..\..\; | ||
//css_ref Wix_bin\SDK\Microsoft.Deployment.WindowsInstaller.dll; | ||
//css_ref WixSharp.UI.dll; | ||
using System; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
using System.Diagnostics; | ||
using System.Security.Principal; | ||
using Microsoft.Deployment.WindowsInstaller; | ||
using WixSharp; | ||
using WixSharp.Forms; | ||
|
||
class Script | ||
{ | ||
static void Main() | ||
{ | ||
var project = | ||
new ManagedProject("ElevatedSetupUI", | ||
new Dir(@"%ProgramFiles%\My Company\My Product", | ||
new File("readme.txt"))); | ||
|
||
project.ManagedUI = ManagedUI.Default; | ||
project.UIInitialized += (SetupEventArgs e) => | ||
{ | ||
if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) | ||
{ | ||
MessageBox.Show(e.Session.GetMainWindow(), "You must start the msi file as admin", e.ProductName); | ||
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); | ||
} | ||
}; | ||
|
||
// For native UI you will need to add managed action implementing restart logic as above | ||
// project.AddAction(new ManagedAction(CustomActions.RestartIfNotAdmin, | ||
// Return.check, | ||
// When.Before, | ||
// Step.AppSearch, | ||
// Condition.NOT_Installed, | ||
// Sequence.InstallUISequence)); | ||
|
||
Compiler.BuildMsi(project); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Source/src/WixSharp.Samples/Wix# Samples/RestartElevated(UI)/uninstall.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
start msiexec /uninstall ElevatedSetupUI.msi |
Binary file not shown.