Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Deployment 将MSMQ作为我申请的先决条件_Deployment_Msmq - Fatal编程技术网

Deployment 将MSMQ作为我申请的先决条件

Deployment 将MSMQ作为我申请的先决条件,deployment,msmq,Deployment,Msmq,我正在开发一个使用MSMQ进行进程间通信的应用程序,如果尚未安装该服务,我需要安装项目来安装该服务。我已经四处查看了关于将其作为先决条件的信息,但到目前为止,我没有找到这个。有什么想法吗?我自己发现了答案……windows组件安装程序不会因为在任何给定时间都无法安装多个MSI而瘫痪,因此我可以使用自定义安装程序操作来执行命令行脚本来安装MSMQ 这是我的安装程序类(您的选项可能明显不同): 公共部分类MSMQInstaller:安装程序 { 公营房屋安装商() { 初始化组件(); } [Dll

我正在开发一个使用MSMQ进行进程间通信的应用程序,如果尚未安装该服务,我需要安装项目来安装该服务。我已经四处查看了关于将其作为先决条件的信息,但到目前为止,我没有找到这个。有什么想法吗?

我自己发现了答案……windows组件安装程序不会因为在任何给定时间都无法安装多个MSI而瘫痪,因此我可以使用自定义安装程序操作来执行命令行脚本来安装MSMQ

这是我的安装程序类(您的选项可能明显不同):

公共部分类MSMQInstaller:安装程序
{
公营房屋安装商()
{
初始化组件();
}
[DllImport(“内核32”)]
静态外部IntPtr加载库(字符串lpFileName);
[DllImport(“kernel32.dll”,SetLastError=true)]
静态外部布尔自由库(IntPtr hModule);
公共覆盖无效安装(IDictionary stateSaver)
{
安装(stateSaver);
bool-loaded;
尝试
{
IntPtr handle=LoadLibrary(“Mqrt.dll”);
if(handle==IntPtr.Zero | | handle.ToInt32()==0)
{
加载=错误;
}
其他的
{
加载=真;
免费图书馆(句柄);
}
}
抓住
{
加载=错误;
}
如果(!已加载)
{
if(Environment.OSVersion.Version.Major<6)//Windows XP或更早版本
{
字符串文件名=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),“MSMQAnswer.ans”);
使用(System.IO.StreamWriter writer=new System.IO.StreamWriter(文件名))
{
writer.WriteLine(“[版本]”);
writer.WriteLine(“签名=\”$Windows NT$\”);
writer.WriteLine();
writer.WriteLine(“[Global]”);
writer.WriteLine(“FreshMode=Custom”);
writer.WriteLine(“MaintenanceMode=RemoveAll”);
writer.WriteLine(“UpgradeMode=UpgradeOnly”);
writer.WriteLine();
writer.WriteLine(“[组件]”);
writer.WriteLine(“msmq_Core=ON”);
WriteLine(“msmq_LocalStorage=ON”);
}
使用(System.Diagnostics.Process p=new System.Diagnostics.Process())
{
System.Diagnostics.ProcessStartInfo start=new System.Diagnostics.ProcessStartInfo(“sysocmgr.exe”,“/i:sysoc.inf/u:\”“+文件名+”\”);
p、 StartInfo=开始;
p、 Start();
p、 WaitForExit();
}
}
else//Vista或更高版本
{
使用(System.Diagnostics.Process p=new System.Diagnostics.Process())
{
System.Diagnostics.ProcessStartInfo start=new System.Diagnostics.ProcessStartInfo(“ocsetup.exe”、“MSMQ容器;MSMQ服务器/被动”);
p、 StartInfo=开始;
p、 Start();
p、 WaitForExit();
}
}
}
}
}

谢谢!!这是VB.Net版本,供感兴趣的人使用

Option Explicit On
Option Strict On

Imports System.Diagnostics.Process
Imports System.IO
Imports System.Text
'Required in all cases when calling API functions
Imports System.Runtime.InteropServices
Imports System.Configuration.Install.Installer

<System.ComponentModel.RunInstallerAttribute(True)> _
Public Class msmqInstaller
    Inherits System.Configuration.Install.Installer

    Private Declare Function LoadLibrary Lib "kernel32" (ByVal lpFileName As String) As IntPtr`enter code here`
    <DllImport("KERNEL32.DLL", EntryPoint:="FreeLibrary", SetLastError:=True)> _
     Public Shared Function FreeLibrary(ByVal hModule As IntPtr) As Boolean
        ' Leave function empty - DLLImport attribute 
        ' forces calls to LoadLibrary to
        ' be forwarded to LoadLibrary in KERNEL32.DLL
    End Function

    Public Const MAX_PATH As Integer = 256
    ' Dim testKernel As loadlibrary
    Dim p As New Process
    '  Dim startInfo As New ProcessStartInfo("sysocmgr.exe", "/i:sysoc.inf /u:\"" + fileName + " \ "")
    Dim fileName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "MSMQAnswer.ans")
    Dim writer As New StreamWriter(fileName)

    ' Override the 'Install' method of the Installer class. When overridden in a derived class, performs the installation.
    'You must override the Install and Uninstall methods to add the code to perform your custom installation steps.
    Public Overrides Sub Install(ByVal mySavedState As IDictionary)
        MyBase.Install(mySavedState)
        Dim loaded As Boolean = False
        Dim fileName As String
        Dim writer As StreamWriter
        Dim p As Process

        Try
            Dim handle As IntPtr = LoadLibrary("Mqrt.dll")
            If handle = IntPtr.Zero Or handle.ToInt32 = 0 Then
                loaded = False
            Else
                loaded = True
                FreeLibrary(handle)
            End If
        Catch ex As Exception
            loaded = False
        End Try

        If Not loaded = True Then
            If Environment.OSVersion.Version.Major < 6 Then ' windows xp or earlier
                fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "MSMQAnswer.ans")
                writer = New System.IO.StreamWriter(fileName)
                Using writer
                    writer.WriteLine("[Version]")
                    '  writer.WriteLine("Signature = \"$Windows NT$\"")
                    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")
                End Using
                p = New System.Diagnostics.Process()
                Using p
                    Dim startInfo As New ProcessStartInfo("sysocmgr.exe", "/i:sysoc.inf /u:\" + fileName + " \ ")
                    p.StartInfo = startInfo
                    p.Start()
                    p.WaitForExit()
                End Using
            Else 'windows vista or later, server 03 
                p = New System.Diagnostics.Process
                Using p
                    Dim startInfo As New ProcessStartInfo("ocsetup.exe", "MSMQ-Container;MSMQ-Server /passive")
                    p.StartInfo = startInfo
                    p.Start()
                    p.WaitForExit()
                End Using
            End If
        End If



    End Sub

End Class
选项显式打开
选项严格限制在
导入System.Diagnostics.Process
导入System.IO
导入系统文本
'调用API函数时,在所有情况下都是必需的
导入System.Runtime.InteropServices
导入System.Configuration.Install.Installer
_
公共类安装程序
继承System.Configuration.Install.Installer
将私有函数LoadLibrary Lib“kernel32”(ByVal lpFileName作为字符串)声明为IntPtr`在此处输入代码`
_
作为布尔值的公共共享函数FreeLibrary(ByVal hModule作为IntPtr)
'将函数留空-DLLImport属性
'将对LoadLibrary的调用强制为
'将被转发到KERNEL32.DLL中的LoadLibrary
端函数
公共常量最大路径为整数=256
'Dim testKernel作为loadlibrary
dimp作为一种新工艺
'Dim startInfo作为新进程startInfo(“sysocmgr.exe”,“/i:sysoc.inf/u:\”“+fileName+”\”)
Dim文件名为String=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),“MSMQAnswer.ans”)
Dim writer作为新StreamWriter(文件名)
'重写安装程序类的'Install'方法。在派生类中重写时,执行安装。
'您必须覆盖安装和卸载方法以添加代码以执行自定义安装步骤。
公共覆盖子安装(ByVal mySavedState作为IDictionary)
MyBase.Install(mySavedState)
加载为布尔值的尺寸=False
将文件名设置为字符串
暗淡无光的作家
dimpas工艺
尝试
作为IntPtr=LoadLibrary(“Mqrt.dll”)的Dim句柄
如果handle=IntPtr.Zero或handle.ToInt32=0,则
已加载=错误
其他的
已加载=真
自由库(句柄)
如果结束
特例
已加载=错误
结束尝试
如果未加载=True,则
如果Environment.OSVersion.Version.Major<6,则“windows xp或更早版本”
fileName=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),“MSMQAnswer.ans”)
writer=New System.IO.StreamWriter(文件名)
使用编写器
writer.WriteLine(“[版本]”)
'writer.WriteLine(“签名=\”$Windows NT$\“”)
writer.WriteLine(“签名=\”“$Windows NT$\”“”)
writer.WriteLine()
writer.WriteLine(“[Global]”)
令状
Option Explicit On
Option Strict On

Imports System.Diagnostics.Process
Imports System.IO
Imports System.Text
'Required in all cases when calling API functions
Imports System.Runtime.InteropServices
Imports System.Configuration.Install.Installer

<System.ComponentModel.RunInstallerAttribute(True)> _
Public Class msmqInstaller
    Inherits System.Configuration.Install.Installer

    Private Declare Function LoadLibrary Lib "kernel32" (ByVal lpFileName As String) As IntPtr`enter code here`
    <DllImport("KERNEL32.DLL", EntryPoint:="FreeLibrary", SetLastError:=True)> _
     Public Shared Function FreeLibrary(ByVal hModule As IntPtr) As Boolean
        ' Leave function empty - DLLImport attribute 
        ' forces calls to LoadLibrary to
        ' be forwarded to LoadLibrary in KERNEL32.DLL
    End Function

    Public Const MAX_PATH As Integer = 256
    ' Dim testKernel As loadlibrary
    Dim p As New Process
    '  Dim startInfo As New ProcessStartInfo("sysocmgr.exe", "/i:sysoc.inf /u:\"" + fileName + " \ "")
    Dim fileName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "MSMQAnswer.ans")
    Dim writer As New StreamWriter(fileName)

    ' Override the 'Install' method of the Installer class. When overridden in a derived class, performs the installation.
    'You must override the Install and Uninstall methods to add the code to perform your custom installation steps.
    Public Overrides Sub Install(ByVal mySavedState As IDictionary)
        MyBase.Install(mySavedState)
        Dim loaded As Boolean = False
        Dim fileName As String
        Dim writer As StreamWriter
        Dim p As Process

        Try
            Dim handle As IntPtr = LoadLibrary("Mqrt.dll")
            If handle = IntPtr.Zero Or handle.ToInt32 = 0 Then
                loaded = False
            Else
                loaded = True
                FreeLibrary(handle)
            End If
        Catch ex As Exception
            loaded = False
        End Try

        If Not loaded = True Then
            If Environment.OSVersion.Version.Major < 6 Then ' windows xp or earlier
                fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "MSMQAnswer.ans")
                writer = New System.IO.StreamWriter(fileName)
                Using writer
                    writer.WriteLine("[Version]")
                    '  writer.WriteLine("Signature = \"$Windows NT$\"")
                    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")
                End Using
                p = New System.Diagnostics.Process()
                Using p
                    Dim startInfo As New ProcessStartInfo("sysocmgr.exe", "/i:sysoc.inf /u:\" + fileName + " \ ")
                    p.StartInfo = startInfo
                    p.Start()
                    p.WaitForExit()
                End Using
            Else 'windows vista or later, server 03 
                p = New System.Diagnostics.Process
                Using p
                    Dim startInfo As New ProcessStartInfo("ocsetup.exe", "MSMQ-Container;MSMQ-Server /passive")
                    p.StartInfo = startInfo
                    p.Start()
                    p.WaitForExit()
                End Using
            End If
        End If



    End Sub

End Class