Try {
    Write-Host -ForegroundColor yellow "`n--- Message Queues ---`n"

    [Reflection.Assembly]::LoadWithPArtialName("System.Messaging") | Out-Null
    $msmq = [System.Messaging.MessageQueue]

    function CreateMessageQueue {
        $name = $args[0]
        $qname = ".\private$\$name"
        If (($msmq::Exists($qname))) {
            $qObject = $msmq::Delete($qname)
        }
        $qObject = $msmq::Create($qname)
        $qObject.SetPermissions("Everyone", [System.Messaging.MessageQueueAccessRights]::FullControl, [System.Messaging.AccessControlEntryType]::Allow)
        $qObject.SetPermissions("ANONYMOUS LOGON", [System.Messaging.MessageQueueAccessRights]::FullControl, [System.Messaging.AccessControlEntryType]::Allow)
    }

    # Cpntroller message queue
    write-host "Creating Controller message queues..." -NoNewline
    CreateMessageQueue "Controller"
    write-host "done."

    # Key/Card Watcher message queue
    write-host "Creating Key/Card Watcher message queue..." -NoNewline
    CreateMessageQueue "Key-Card-Watcher"
    write-host "done."


    # Display message queues (to alert the Services when the Display App is running)
    write-host "Creating Display message queues..." -NoNewline
    CreateMessageQueue "Display-SMS"
    CreateMessageQueue "Display-SMS-Media-Status"
    write-host "done."


    # State Machine message queues
    write-host "Creating State Machine message queues..." -NoNewline
    CreateMessageQueue "SMS-Display"
    CreateMessageQueue "SMS-Controller"
    CreateMessageQueue "SMS-Token"
    CreateMessageQueue "Action-SMS"
    write-host "done."

    # Sync message queues
    write-host "Creating Sync message queue..." -NoNewline
    CreateMessageQueue "Sync-Token"
    write-host "done."
}
Catch {
    throw $_.Exception.Message
}
