Tôi đang làm việc trên một ứng dụng sử dụng MSMQ cho liên lạc liên tiến trình và tôi cần dự án thiết lập để có thể cài đặt dịch vụ nếu chưa có. Tôi đã kiểm tra xung quanh để biết thông tin về làm cho nó là một điều kiện tiên quyết, nhưng cho đến nay tôi đã không thành công trong việc tìm kiếm này. Ý tưởng nào?Bao gồm MSMQ làm điều kiện tiên quyết cho đơn đăng ký của tôi
Trả lời
Phát hiện câu trả lời của riêng mình ... trình cài đặt thành phần không bị tê liệt do không có khả năng cài đặt nhiều hơn một MSI vào bất kỳ thời điểm nào, vì vậy tôi có thể sử dụng hành động cài đặt tùy chỉnh để thực thi lệnh dòng lệnh để cài đặt MSMQ.
Đây là lớp Installer của tôi (tùy chọn của bạn rõ ràng là có thể thay đổi):
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();
}
}
}
}
}
cảm ơn !! Đây là phiên bản VB.Net cho bất kỳ ai quan tâm.
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
Còn lệnh pkgmgr thì sao?
pkgmgr/iu: MSMQ-Container; MSMQ-Server
Điều đó dường như đang làm điều tương tự như 'ocsetup.exe' trong câu trả lời của tôi. –
Nhưng ocsetup không hiện diện theo mặc định tại Windows 8.1 – Miguel
- 1. Cách có điều kiện bao gồm một số đơn vị
- 2. đăng ký msmq
- 3. ClickOnce Điều kiện tiên quyết - Cách quản lý thứ tự cài đặt của Điều kiện tiên quyết?
- 4. biến Makefile là điều kiện tiên quyết
- 5. Triển khai web ASP.NET chỉ với một cú nhấp chuột bao gồm các điều kiện tiên quyết?
- 6. Làm điều kiện tiên quyết LUÔN phải được kiểm tra?
- 7. WCF Xuất bản/Đăng ký với MSMQ
- 8. MSMQ và Đăng nhập
- 9. có điều kiện bao gồm các nút con với RABL
- 10. Điều kiện tiên quyết để học Máy học là gì?
- 11. Truy vấn EF với điều kiện bao gồm
- 12. thêm "Microsoft Access Database Engine 2010 Redistributable" làm điều kiện tiên quyết cho clickonce
- 13. SQL CE 4.0 là InstallShield Điều kiện tiên quyết
- 14. Điều kiện tiên quyết để hiểu lý thuyết Wavelet
- 15. Làm cách nào để có điều kiện bao gồm tệp trong mẫu của tôi bằng JSF và Facelets?
- 16. Theo dõi đăng ký, bao gồm truy cập đăng ký chế độ lõi?
- 17. ActiveRecord to_json: có điều kiện bao gồm các liên kết
- 18. Cách sử dụng Bảng Quyết định để giúp đơn đăng ký của bạn
- 19. Bao gồm thẻ có điều kiện trong Rails/ERB
- 20. Thẻ có điều kiện bao gồm trong Django
- 21. có điều kiện bao gồm thuộc tính trong XML đen
- 22. Thiếu điều kiện tiên quyết cho Visual C++ trong Visual Studio 2012
- 23. Tôi có thể có được điều kiện tiên quyết thứ hai trong GNU?
- 24. Bao gồm API slf4j
- 25. Tại sao đơn đăng ký của tôi xuất hiện 4 lần trên thiết bị của tôi?
- 26. thực hiện: thực hiện một hành động cho mỗi điều kiện tiên quyết
- 27. Bao gồm/loại trừ tài nguyên có điều kiện cho apk Android xây dựng
- 28. Nhiều người đăng ký tham gia sự kiện ASP.NET UserControl đơn lẻ?
- 29. Bật Điều kiện tiên quyết tải xuống từ cùng một vị trí với ứng dụng của tôi
- 30. Đơn đăng ký hoạt động đơn lẻ
Đó là bánh quy giòn. Cảm ơn bạn đã chia sẻ. –
Làm thế nào để bạn gọi phương thức cài đặt? Tôi đã thêm tham chiếu 'system.configuration.Install' Phương thức InitializeComponent là một phương thức trong cơ sở? làm thế nào tôi có thể sử dụng lớp này để cài đặt msmq? –
@Adam: Bạn đã lấy một thư viện lớp riêng cho lớp trình cài đặt này chưa? Tôi gặp lỗi "Không thể tìm thấy InitializeComponent" khi tôi sử dụng mã của bạn. – Abhishek