Je travaille sur une application qui utilise MSMQ pour la communication interprocessus, et j'ai besoin du projet d'installation pour pouvoir installer le service si ce n'est déjà fait. J'ai vérifié autour de l'information sur en faire une condition préalable, mais jusqu'ici je n'ai pas réussi à trouver ceci. Des idées?Inclure MSMQ comme prérequis pour mon application
Répondre
Découvert la réponse par moi-même ... le programme d'installation de composants Windows n'est pas paralysé par l'incapacité typique d'installer plus d'un MSI à un moment donné, donc je peux utiliser une action d'installation personnalisée pour exécuter une commande script de ligne pour installer MSMQ.
Voilà ma classe d'installation (vos options peuvent évidemment varier):
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();
}
}
}
}
}
Merci !! Voici la version VB.Net pour tous ceux qui sont intéressés.
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
Qu'en est-il de la commande pkgmgr? Pkgmgr/iu: conteneur MSMQ; serveur MSMQ
Cela semble faire la même chose que 'ocsetup.exe' dans ma réponse. –
Mais ocsetup n'est pas présent par défaut sous Windows 8.1 – Miguel
- 1. Géré DirectX comme prérequis
- 2. Comment inclure une police avec mon application iPhone?
- 3. Puis-je inclure un fichier XML personnalisé dans mon application pour le contenu par défaut?
- 4. Tutoriel pour mon application Yahoo
- 5. Comment inclure JavaHelp avec mon projet Eclipse?
- 6. Pour utiliser MSMQ ou WCF - VS 2008
- 7. Wix et .NET Framework (prérequis)
- 8. Zend Framework + Une API pour mon application
- 9. SQL Server comme prérequis dans le programme d'installation de VS Erreur de projet dans Windows Vista
- 10. Besoin d'un moyen de présenter un prérequis pour un objet
- 11. <ProjectName.ProjectUI suce comme nom pour mon application NetBeans java OS X
- 12. Comment inclure des contrôles spécifiques de System.Windows.Controls dans mon application Silverlight?
- 13. popup toast style pour mon application
- 14. Puis-je inclure un contrôleur de navigation dans mon projet?
- 15. Prérequis pour la compréhension de la théorie des ondelettes
- 16. MSMQ 3.0/4.0 télécharger
- 17. MSMQ n'invoquant pas COM
- 18. Moniteur MSMQ
- 19. Windows Mobile - package mp3 avec mon application
- 20. Comment "publier" mon application?
- 21. STDIN.getc verrouillage mon application
- 22. Redondance MSMQ
- 23. Surveillance MSMQ
- 24. Évolutivité MSMQ
- 25. Javascript Inclure la meilleure pratique d'étiquette dans une application Rails
- 26. Directory comme un seau pour une application ClickOnce
- 27. .NET ClickOnce n'installe pas les fichiers prérequis?
- 28. Comment rendre mon application intégrée?
- 29. Reconnaissant mon application dans iTunes
- 30. Fournir la version à seulement les prérequis dans clickonce
Merci pour le partage. –
Comment appelez-vous la méthode d'installation? J'ai déjà ajouté la référence 'system.configuration.Install' La méthode InitializeComponent est une méthode dans la base? comment puis-je utiliser cette classe pour installer msmq? –
@Adam: Avez-vous pris une bibliothèque de classes séparée pour cette classe d'installateur? Je reçois une erreur "Impossible de trouver InitializeComponent" lorsque j'utilise votre code. – Abhishek