2011-04-05 5 views
10

MSMQ에서 개인 큐로 추가해야하는 20 개가 넘는 큐 목록이 있습니다.프로그래밍 방식으로 MSMQ에 개인 큐 추가

  1. 명령 줄을 사용하여 할 수있는 방법이 있나요

  2. C# 프로그래밍 스크립트 또는 어떤 종류를 사용 할 수있는 방법이 있다면

.NET 프로그래밍 그럼 수동으로 그것을 입력하고 오타가 발생하지 않고 추가 할 수 있습니다.

알려 주시기 바랍니다.

감사

답변

18
using System.Messaging; 

//... 

void CreateQueue(string qname) { 
    if (!MessageQueue.Exists(qname)) MessageQueue.Create(qname); 
} 

에만 로컬 컴퓨터의 개인 큐를 만들 수 있습니다. 자세한 내용은 다음을 참조하십시오 Creating Queues

+0

리차드, C에서 프로그래밍 방식으로 권한을 설정하는 방법을 알고 계십니까? – irvinedotnet

+0

AccessControlList를 사용하여 사용 권한을 설정 한 다음 "queue.SetPermissions()"를 설정합니다. MessageQueue.Create는 큐를 반환합니다. –

+0

이것은 나를 위해 일했다 .. 감사합니다 – irvinedotnet

2

명령 행를 들어, 다음과 같은 내용으로 .vbs 파일을 만들 수 있습니다

Option Explicit 

Dim objInfo 
Dim objQue 
Dim objMsg 
Dim strFormatName ' Destination 

strFormatName = "direct=os:.\private$\test" 

Set objInfo = CreateObject("MSMQ.MSMQQueueInfo") 
Set objMsg = CreateObject("MSMQ.MSMQMessage") 

objMsg.Label = "my message" 
objMsg.Body = "This is a sample message." 
objInfo.FormatName = strFormatName 
set objQue = objInfo.Open(2, 0) 

' Send Message 
objMsg.Send objQue 

' Close Destination 
objQue.Close 

Set objMsg = Nothing 
Set objInfo = Nothing 

msgbox "Done..." 
0

조금 늦게에,하지만 난 단지 지금 작업을 시작했다.

Richard의 답변에 추가하면 공개 대기열을 만들 수 있습니다. 호스트 이름과 해당 컴퓨터에 대한 관리자 권한이 필요합니다.

public static MessageQueue CreatePrivate(string name) { 
     string path = string.Format(@".\private$\{0}", name); 
     if (!MessageQueue.Exists(path)) { 
      MessageQueue.Create(path); 
      return new MessageQueue(path); 
     } 
     return new MessageQueue(path); 
    } 

    public static MessageQueue CreatePublic(string hostname,string queuename) { 
     string path = string.Format(@"{0}\{1}", hostname,queuename); 
     if (!MessageQueue.Exists(path)) { 
      MessageQueue.Create(path); 
      return new MessageQueue(path); 
     } 
     return new MessageQueue(path); 
    } 
} 
관련 문제