Deepthi 的个人资料Win with Win Mobile照片日志列表更多 工具 帮助

日志


12月22日

Managed Wrapper for Installing MSMQ on Pocket PC

Msmq 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 service

ExecuteMSMQAdm(

"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 :).

 

 

评论 (1)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

hpuneet发表:
Hey deepthi.. great to know that ur maintaining a tech blog space..kewl...sooper kewl
1 月 4 日

引用通告

此日志的引用通告 URL 是:
http://winwithmobility.spaces.live.com/blog/cns!A2CD686F55CB1049!124.trak
引用此项的网络日志