Getting an access denied error when trying to pause/resume an outgoing message queue - vb.net

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
Here is the code I am using, by sending the test message to a non-existing path it gets stuck in the outgoing queue where I want to be able to call MSMQOutgoingQueueManagement.Pause or .Resume to be able to start and stop all outgoing queues.
However I keep getting an error on either mgmt.Pause() or mgmt.Resume() saying Access is denied. I can't seem to find a way to get on to the properties of outgoing queues to be able to adjust security settings. Any help would be greatly appreciated!

SOLVED!
Turns out I just needed to start up visual studio as an administrator and then it worked.

Related

Vb.Net compiling error

When I try and run my program in debug i keep receiving an error BC30456 it reads as follows:
Severity Code Description Project File Line Suppression State
Error BC30456 'Form1' is not a member of 'serialtest2'. serialtest2 C:\Users\Rhans\Desktop\VB6 Programs\Ethernet Socket\serialtest2\My Project\Application.Designer.vb 35 Active
I am looking to monitor a serial port that has a mettler toledo scale hooked to it and I am trying to display a continuous weight on the form...
Any help would be greatly appreciated.
The code is as follows:
Imports System.IO.Ports
Imports System.IO.Ports.SerialPort
Public Class SerialCommunication
Private WithEvents Port As New SerialPort
Private Sub SerialCommunication_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With Port
.PortName = "COM5"
.RtsEnable = True
.BaudRate = 9600
.Open()
End With
End Sub
Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Port.DataReceived
Dim buffer As String = Port.ReadExisting()
txtDisplay.Text = buffer
End Sub
Your SerialCommunication Class replaces Form1 by the looks of it.
Go to Project > Properties then select Startup Form: Serial Communication or change the name of your class to "Form1" instead of "SerialCommunication"
I had the same problem and my solution came from Web.config. I had removed the default language from compilation node. When i put it back it worked fine.
<compilation debug="true" defaultLanguage="vb" targetFramework="4.5.2">

Acess to the path is denied vb.net

Why I'm i seeing this message. I just wanted to add the application to start each time with windows and then it popups me this message.
Access to the path .... is denied.
I add to startup with this code
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim info As New FileInfo(Application.StartupPath)
info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\Apps.exe")
End Sub
If you want that your application to start on windows startup you can use the registry.
To add an application to the system use this code -
Imports Microsoft.Win32
Public Sub RunAtStartup(ByVal ApplicationName As String, ByVal ApplicationPath As String)
Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
With CU
.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
.SetValue(ApplicationName, ApplicationPath)
End With
End Sub
And to use the function just do -
RunAtStartup(Application.ProductName,Application.ExecutablePath)

EWS SubscribeToPullNotifications does not get new emails

I had the following code written using EWS to subscribe to Pull notifications and read new emails. It was working all fine. All of a sudden it does not read the new emails. Any ideas what could the cause be? And how to resolve it?
Imports Microsoft.Exchange.WebServices.Data
Imports System.Threading
Public Class FormTest
Dim subscription As PullSubscription
Dim service As ExchangeService
Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
service = New ExchangeService
service.Credentials = New WebCredentials("myusername", "mypassword", "mydomain")
service.Url = New Uri("https://webmail.mydomain.com/EWS/exchange.asmx")
subscription = service.SubscribeToPullNotifications(New FolderId() {WellKnownFolderName.Inbox}, 1440, Nothing, EventType.NewMail)
End Sub
Private Sub ButtonPoll_Click(sender As Object, e As EventArgs) Handles ButtonPoll.Click
PollEmails()
End Sub
Private Sub PollEmails()
Dim events As GetEventsResults = subscription.GetEvents()
For Each itemEvent As ItemEvent In events.ItemEvents
Dim message As EmailMessage = EmailMessage.Bind(service, itemEvent.ItemId)
message.Load()
' Do something with 'message'
Next
End Sub
End Class
Basically when I press ButtonPoll events does not contain any new evenets, even though there has been new emails since the ButtonStart was pressed.
Heyo!! I am doing something very similar. Looks like you have posted this question a month and a half ago so you may have solved it by now, but I wanted to put my initial experiences up here for anyone else that may be looking. The way I am posting below is a way to get notifications without having to push a poll button. This may help! I stripped all my fancy stuff out, as it is always important to learn, but this initial part of it was the most obnoxious part to figure out.
Imports System.Net
Imports System.Net.Security
Imports Microsoft.Exchange.WebServices.Data
Imports System.Security.Cryptography.X509Certificates
Public Class MainForm
Private Sub ExecuteButton_Click(sender As System.Object, e As System.EventArgs) Handles ExecuteButton.Click
Console.Clear()
Dim exch As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2010_SP2)
exch.Url = New Uri("https://" + ExchangeURLTB.Text + "/EWS/Exchange.asmx")
exch.UseDefaultCredentials = False
exch.Credentials = New System.Net.NetworkCredential(UsernameTB.Text, PasswordTB.Text, DomainTB.Text)
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
Dim subscribeStreaming As StreamingSubscription = exch.SubscribeToStreamingNotifications(New FolderId() {WellKnownFolderName.Inbox}, EventType.NewMail, EventType.Created, EventType.Deleted)
Dim subscribeStreamingConnection = New StreamingSubscriptionConnection(exch, 30)
subscribeStreamingConnection.AddSubscription(subscribeStreaming)
AddHandler subscribeStreamingConnection.OnNotificationEvent, AddressOf OnNotificationEvent
AddHandler subscribeStreamingConnection.OnSubscriptionError, AddressOf OnSubscriptionError
AddHandler subscribeStreamingConnection.OnDisconnect, AddressOf OnDisconnect
subscribeStreamingConnection.Open()
Console.Write("Steaming subscription open")
End Sub
Private Sub OnNotificationEvent(sender As Object, args As NotificationEventArgs)
Dim subscription As StreamingSubscription = args.Subscription
For Each notification As NotificationEvent In args.Events
Select Case notification.EventType
Case EventType.NewMail
Console.WriteLine(vbNewLine)
Console.WriteLine("-------------Mail created:-------------")
End Select
Next
End Sub
Private Sub OnSubscriptionError(sender As Object, args As SubscriptionErrorEventArgs)
End Sub
Private Sub OnDisconnect(sender As Object, args As SubscriptionErrorEventArgs)
End Sub
Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
'Return True to force the certificate to be accepted.
Return True
End Function
End Class

How is it possible to parse the URL of the desired popup to the popup-form AND show hints/tooltips in the WebKit-Component?

I'm trying to use the WebKit-component (http://www.webkit.org/) in VB with the help of Visual Studio 2008.
This is running without problems, except for two following two issues:
1. Hints/Tooltips are not shown (e.g. as there usually will appear one if you stay with the mouse over the Google-logo)
2. If there's a popup-window, I don't know how to get the new desired URL.
I'm already working a few days on this matter and couldn't find any solution yet :(
Maybe you know a solution to this problem.
Cheers
Markus G.
P.S.: If you need more than the following Source Code to analyze the problem, then let me know ...
Source Code Form1
Imports System.IO
Imports WebKit
Public Class frmMain
Private _url As String
Private _mode As String
Private _popupUrl As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
Dim bLogging As Boolean
setWindowAndBrowserSettings()
_url = "http://www.google.com"
browserComp.Navigate(_url)
End Sub
Private Sub setWindowAndBrowserSettings()
Me.Text = "Test - Browser"
Me.WindowState = FormWindowState.Maximized
browserComp.Dock = DockStyle.Fill
browserComp.Visible = True
End Sub
Private Sub browserComp_NewWindowCreated(ByVal sender As Object, ByVal e As WebKit.NewWindowCreatedEventArgs) Handles browserComp.NewWindowCreated
'frmPopup.WindowState = FormWindowState.Maximized
frmPopup.Text = "ixserv - POPUP"
frmPopup.popup.Navigate(_popupUrl)
frmPopup.Show()
End Sub
Private Sub browserComp_NewWindowRequest(ByVal sender As Object, ByVal e As WebKit.NewWindowRequestEventArgs) Handles browserComp.NewWindowRequest
e.Cancel = False
_popupUrl = browserComp.Url.ToString ' WHERE can I get the clicked URL? This is the old one of the remaining window
End Sub
End Class
Code Form2
Public Class frmPopup
End Class
Following popup/new-Window-Create-function works for me:
Private Sub browserComp_NewWindowCreated(ByVal sender As Object, ByVal e As WebKit.NewWindowCreatedEventArgs) Handles browserComp.NewWindowCreated
frmPopup.Text = "POPUP"
Dim popupBrowser As WebKit.WebKitBrowser
popupBrowser = e.WebKitBrowser
frmPopup.Controls.Add(popupBrowser)
frmPopup.Show()
End Sub
whereas frmPopup is a new form.
Before I tried this I already added the Webkit-component to the new form, which might had been the problem. I assume, the trick is, to create a new WebKitBrower-element that is directly connected to the argument e.WebkitBrowser instead of overloading an existing webkitbrowser-component in the form. Don't ask me for reasons for this now (I really don't know) :P
Oh, I should add that I used the Webkit.NET component. The same trick works also for the OpenWebkitSharp-wrapper
The hint-problem still remains ...

System.Threading.Timer not firing, global.aspx

I am a newbie, but I am unable to get this code working. FileSweeper is supposed to start a timmer that triggers fileCopy on a web server. fileSweeoer is triggered by global.asax. FileCopy then will copy the file. However the FC.copy never fires. Any help/explanation would be helpful!
Would it make any difference if this was a class running on a web server?
My code is from http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx.
Imports Microsoft.VisualBasic
Imports System
Imports System.Threading
Public Class fileSweeper
Dim stateTimer As Timer
<MTAThread()> _
Sub Main()
Dim FC As New fileCopy
Dim tcb As TimerCallback = AddressOf FC.Copy
stateTimer = New Timer(tcb, "", 20000, 200000)
GC.KeepAlive(stateTimer)
End Sub
End Class
Global.asax:
<%# Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Dim FS As New fileSweeper
FS.Main()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
</script>
You are probably going to get unexpected results here because you are likely going to get multiple sessions on a web server. You might want to consider creating a console app and using windows task scheduler.