我正在开发一个使用MSMQ进行进程间通信的应用程序,我需要安装项目才能安装该服务(如果尚未安装).我已经查看了有关使其成为先决条件的信息,但到目前为止,我一直未能找到这个.有任何想法吗?
Ada*_*son 26
我自己发现了答案...... Windows组件安装程序并没有因为在任何给定时间无法安装多个MSI而瘫痪,因此我可以使用自定义安装程序操作来执行命令行脚本来安装MSMQ.
这是我的安装程序类(您的选项可能明显不同):
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();
                }
            }
        }
    }
}
| 归档时间: | 
 | 
| 查看次数: | 7497 次 | 
| 最近记录: |