Deepthi 的个人资料Win with Win Mobile照片日志列表更多 ![]() | 帮助 |
|
12月22日 Managed Wrapper for Installing MSMQ on Pocket PCMsmq component is bundled with the OS. We need to install it as a separate cab file from the following link :
In my blog post titled 'Message Queues in .net CF' ,I mentioned the steps that need to be followed to install the msmq cab file manually.
Here's a wrapper class that will do the same through code. What I have done is call the processes that are required to be called to install,register,start and stop msmq. Also we can enable srmp and binary protocols through this wrapper.
using System;using System.Diagnostics;using System.IO;using System.Runtime.InteropServices;namespace MessagingQueueWrapper { public class MessagingQueueWrapperClass { [ DllImport("CoreDll.dll")] private extern static Int32 GetLastError();[ DllImport("CoreDll.dll")] private extern static Int32 CloseHandle(IntPtr hProcess);[ DllImport("CoreDll.dll")] private extern static IntPtr ActivateDevice( string lpszDevKey, Int32 dwClientInfo); //Execute commands on the MSMQAdm.exe utility public static bool ExecuteMSMQAdm(String CmdLine){ Process prc = Process.Start(@"\windows\msmqadm.exe", CmdLine); if (prc == null) throw new ApplicationException("Process already running");prc.WaitForExit(); if (prc.ExitCode != 0) return false; else return true;} //This is the MSMQAdm.exe utility we’ll be using private const String MSMQ_ADM = @"\windows\msmqadm.exe"; private const String MSMQ_DRIVER_REG = @"Drivers\BuiltIn\MSMQD"; private const string MsmqLogFilePath = @"\windows\MsmqLogFile"; public enum MsmqErrorCodes{ Success, RegisterInstallFailed, RegisterFailed, EnableBinaryFailed, EnableSrmpFailed, StartFailed, StatusFailed }; public static MsmqErrorCodes StartMSMQ() { //Check status of MSMQ (is it installed and running yet? if (!(ExecuteMSMQAdm("status"))){ //Deletes the MSMQ registry key and store directory. //All messages are lost.ExecuteMSMQAdm( "register cleanup"); //Installs MSMQ as device drivers. if (!ExecuteMSMQAdm("register install")){ return MsmqErrorCodes.RegisterInstallFailed;} //Creates the MSMQ Configuration in Registry if (!ExecuteMSMQAdm("register")){ return MsmqErrorCodes.RegisterFailed;} //Enables the native MSMQ protocol if (!ExecuteMSMQAdm("enable binary")){ return MsmqErrorCodes.EnableBinaryFailed;} //Starts the MSMQ service if (!ExecuteMSMQAdm("start")){ //This is one additional step that is needed for PocketPCs //The Device Drivers have to be loaded before the service //can be started //ActivateDevice will load the device drivers IntPtr handle = ActivateDevice(MSMQ_DRIVER_REG, 0);CloseHandle(handle); //Let us check if MSMQ is running if (!ExecuteMSMQAdm("status")){ return MsmqErrorCodes.StatusFailed;} return MsmqErrorCodes.StartFailed;} return MsmqErrorCodes.Success;} else return MsmqErrorCodes.Success;} public static MsmqErrorCodes EnableSrmp(){ //Check status of MSMQ (is it installed and running yet? if (!(ExecuteMSMQAdm("status"))){ MessagingQueueWrapper. MessagingQueueWrapperClass.StartMSMQ();} //Starts the MSMQ serviceExecuteMSMQAdm( "stop"); //Enables the native MSMQ protocol if (!ExecuteMSMQAdm("enable srmp")){ return MsmqErrorCodes.EnableSrmpFailed;} if (!ExecuteMSMQAdm("start")){ return MsmqErrorCodes.StartFailed;} else return MsmqErrorCodes.Success;} } }
How to use : Create a class library and copy-paste this code in that, build it and add a reference to this dll (MessageQueueWrapper) in ur project. In the FormLoad method, you can call the install and enable methods like this: if (MessagingQueueWrapper.MessagingQueueWrapperClass.StartMSMQ() == MessagingQueueWrapper.MessagingQueueWrapperClass.MsmqErrorCodes.Success) MessageBox.Show("Success in installing"); if (MessagingQueueWrapper.MessagingQueueWrapperClass.EnableSrmp() == MessagingQueueWrapper.MessagingQueueWrapperClass.MsmqErrorCodes.Success) MessageBox.Show("Success in enabling srmp");And lo ! MSMQ is installed on ur device ! Hope that helps :)..I spent quite a few days trying to figure out how to enable srmp manually...this should save us all the trouble :).
引用通告此日志的引用通告 URL 是: http://winwithmobility.spaces.live.com/blog/cns!A2CD686F55CB1049!124.trak 引用此项的网络日志
|
|
|