私はプロセス間通信にMSMQを使用するアプリケーションで作業しています。まだインストールされていない場合は、セットアッププロジェクトが必要です。私はそれを前提条件にするための情報を確認しましたが、これまで私はこれを見つけていませんでした。何か案は?私のアプリケーションの前提条件としてMSMQを含める
21
A
答えて
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();
}
}
}
}
}
3
はありがとうございました!!興味がある人は誰でも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
5
pkgmgrコマンドはどうですか?
pkgmgr/iu:MSMQ-Container; MSMQ-Server
+0
それは私の答えで 'ocsetup.exe'と同じことをしているようです。 –
+4
しかし、ocsetupはWindows 8.1ではデフォルトでは存在しません – Miguel
関連する問題
- 1. msiの前提条件としてMS Access 2007ランタイムを含める方法
- 2. 前提条件とクラス封じ込め
- 3. シーケンス図に前提条件を含めるか?例えば
- 4. InstallShieldを使用してセットアッププロジェクトの前提条件としてAdobe Flash Playerを含める
- 5. 前提条件とデータベースとの対話
- 6. Clickonceアップデートインストールの前提条件
- 7. JSPプロジェクトの前提条件
- 8. クライアントプロファイルアプリケーションの前提条件
- 9. RPMパッケージの前提条件
- 10. 前提条件のUML?
- 11. VBアプリケーション用のWindows Server 2012にCDO.DLLをインストールするための前提条件
- 12. オンラインスカイプウェブSDKのビジネスにWebアプリケーションを統合するための前提条件
- 13. Django/Pythonアプリケーションと開発者環境の前提条件
- 14. セットアップ展開プロジェクトに含めるSQL Server Express 64ビットの前提条件
- 15. パブリックメソッドでの前提条件と事後条件チェック
- 16. ASP.NETアプリケーションをインストールするための前提条件は何ですか?
- 17. ネイティブスマートフォンアプリを作成するためのウェブサイトの前提条件
- 18. Makefileの前提条件としてのターゲット固有の変数
- 19. powershellを前提条件としてインストールするには?
- 20. .netframeworkを前提条件としてインストールする
- 21. ウェーブレット理論を理解するための前提条件
- 22. Pact Contract Testingを開始するための前提条件
- 23. 前提条件スウィフト3
- 24. セットアッププロジェクト.net 4前提条件
- 25. nixos + haskell + opengl(前提条件)
- 26. メイク:各前提条件
- 27. 方法前提条件
- 28. InstallShieldとしてのSQL CE 4.0前提条件
- 29. make前提条件のファイルリストを使用
- 30. WiXの条件付き前提条件の指定
これはクラッカーです。共有していただきありがとうございます。 –
インストール方法はどのように呼びますか?私は既にリファレンス 'system.configuration.Install'を追加しました。InitializeComponentメソッドはベースのメソッドですか?このクラスを使用してmsmqをインストールするにはどうすればよいですか? –
@Adam:このインストーラクラス用に別のクラスライブラリを用意しましたか?あなたのコードを使用すると、「InitializeComponentが見つかりません」というエラーが表示されます。 – Abhishek