Test Custom Actions During Install Deployment
In researching a MSDN forum question I needed to see the current user’s credentials during a custom action during an Setup and Deployment project created from a Visual Studio 2005 project. My goal was to show a message box during install that would display the user’s credentials and domain.
What makes this project unique is that we will be using MessageBox, from the System.Windows.Forms namespace. This article shows you how to utilize a MessageBox in a custom action. Here are the steps
- Using this article as a basis Walkthrough: Creating a Custom Action we will do everything it does except do a Commit action.
- Add a reference to the dll project to include the System.Windows.Form namespace which will not be included by default.
- In the custom installer class created in the helper dll override the Install Method such as:
[RunInstaller(true)]
public partial class ShowInfo : Installer
{
public ShowInfo()
{
InitializeComponent();
}
// Add and override this method to show the current user and the domain.
public override void Install(System.Collections.IDictionary stateSaver)
{
WindowsIdentity wi = WindowsIdentity.GetCurrent();
MessageBox.Show(string.Format("Name :{0}{1}System {2}", wi.Name, Environment.NewLine, Environment.UserDomainName));
base.Install(stateSaver);
}
}
Then add these usings to the top of the file:using System.Windows.Forms;
using System.Security.Principal;
- Then in the install project unlike the Walkthrough, add the custom dll to the Custom Actions operation in the Install Node.
- Build and install. Note the message box may come up behind other windows during install, so you may have to look.
This is a quick way to show information during an install for debug purposes or user info. Note it is a modal dialog and will stop processing until the user closes the message box window.