簡體   English   中英

嘗試暫停/恢復傳出消息隊列時出現訪問被拒絕錯誤

[英]Getting an access denied error when trying to pause/resume an outgoing message queue

Imports System.Messaging
Imports System.Collections
Imports MSMQ
Imports System.IO
Imports System
Imports System.Messaging.MessageQueue
Imports System.Runtime.InteropServices

Public Class PauseOutMessages
    'Declare everything to be in the scope of all methods.
    Dim mgmt As New MSMQManagement
    Dim outqmgmt As MSMQOutgoingQueueManagement
    Dim q As New MSMQApplication
    Dim outgoingQueues As New ArrayList
    Dim myQueue As New MessageQueue("FormatName:DIRECT=OS:myMachine\Private$\myQueue", QueueAccessMode.ReceiveAndAdmin)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        For Each queue In q.ActiveQueues
            If queue.IndexOf("DIRECT=") >= 0 Then
                outgoingQueues.Add(queue)
            End If
        Next

    End Sub

    Private Sub Pause_Click(sender As Object, e As EventArgs) Handles Pause.Click
        For Each queuePath In outgoingQueues
            mgmt.Init(FormatName:=queuePath)
            outqmgmt = mgmt.Pause()
        Next
    End Sub

    Private Sub Restart_Click(sender As Object, e As EventArgs) Handles Restart.Click
        For Each queuePath In outgoingQueues
            mgmt.Init(FormatName:=queuePath)
            outqmgmt = mgmt.Resume()
        Next
    End Sub

    Private Sub Send_Click(sender As Object, e As EventArgs) Handles Send.Click
        myQueue.Send("Test")
        For Each queue In q.ActiveQueues
            If queue.IndexOf("DIRECT=") >= 0 Then
                outgoingQueues.Add(queue)
            End If
        Next
    End Sub
End Class

這是我正在使用的代碼,通過將測試消息發送到一個不存在的路徑,它會卡在傳出隊列中,我希望能夠調用 MSMQOutgoingQueueManagement.Pause 或 .Resume 來啟動和停止所有傳出隊列.

但是,我一直在 mgmt.Pause() 或 mgmt.Resume() 上收到錯誤,說訪問被拒絕。 我似乎無法找到一種方法來了解傳出隊列的屬性以調整安全設置。 任何幫助將不勝感激!

解決了!

原來我只需要以管理員身份啟動 Visual Studio,然后它就可以工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM