Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including MSMQ as a prerequisite for my application

Tags:

I'm working on an application that uses MSMQ for interprocess communication, and I need the setup project to be able to install the service if it isn't already. I've checked around for information on making it a prerequisite, but so far I've been unsuccessful at finding this. Any ideas?

like image 852
Adam Robinson Avatar asked Mar 25 '09 17:03

Adam Robinson


People also ask

How do I install MSMQ on Windows 11?

1. Type Start PowerShell in the Command Prompt window to start Windows PowerShell. 2. Type Install-WindowsFeature MSMQ-Services and press Enter to install the Message Queuing feature.


2 Answers

Discovered the answer on my own...the windows component installer is not crippled by the typical inability to install more than one MSI at any given time, so I'm able to use a custom installer action to execute a command line script to install MSMQ.

Here's my Installer class (your options may obviously vary):

public partial class MSMQInstaller : Installer {     public MSMQInstaller()     {         InitializeComponent();     }      [DllImport("kernel32")]     static extern IntPtr LoadLibrary(string lpFileName);      [DllImport("kernel32.dll", SetLastError = true)]     static extern bool FreeLibrary(IntPtr hModule);      public override void Install(IDictionary stateSaver)     {         base.Install(stateSaver);          bool loaded;          try         {             IntPtr handle = LoadLibrary("Mqrt.dll");              if (handle == IntPtr.Zero || handle.ToInt32() == 0)             {                 loaded = false;             }             else             {                 loaded = true;                  FreeLibrary(handle);             }         }         catch         {             loaded = false;         }          if (!loaded)         {             if (Environment.OSVersion.Version.Major < 6) // Windows XP or earlier             {                 string fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "MSMQAnswer.ans");                  using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName))                 {                     writer.WriteLine("[Version]");                     writer.WriteLine("Signature = \"$Windows NT$\"");                     writer.WriteLine();                     writer.WriteLine("[Global]");                     writer.WriteLine("FreshMode = Custom");                     writer.WriteLine("MaintenanceMode = RemoveAll");                     writer.WriteLine("UpgradeMode = UpgradeOnly");                     writer.WriteLine();                     writer.WriteLine("[Components]");                     writer.WriteLine("msmq_Core = ON");                     writer.WriteLine("msmq_LocalStorage = ON");                 }                  using (System.Diagnostics.Process p = new System.Diagnostics.Process())                 {                     System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo("sysocmgr.exe", "/i:sysoc.inf /u:\"" + fileName + "\"");                      p.StartInfo = start;                      p.Start();                     p.WaitForExit();                 }             }             else // Vista or later             {                 using (System.Diagnostics.Process p = new System.Diagnostics.Process())                 {                     System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo("ocsetup.exe", "MSMQ-Container;MSMQ-Server /passive");                      p.StartInfo = start;                      p.Start();                     p.WaitForExit();                 }             }         }     } } 
like image 89
Adam Robinson Avatar answered Nov 22 '22 11:11

Adam Robinson


What about the pkgmgr command?

pkgmgr /iu:MSMQ-Container;MSMQ-Server

like image 25
Scott Gowell Avatar answered Nov 22 '22 13:11

Scott Gowell