Visual Studio 2019 Open URL In Browser Using VB - vb.net

I am trying to use a LinkLabel to direct users of my program to my Discord server (so they can report bugs and whatnot), but every time I click on it I get an error saying 'The system cannot find the file specified.'
I was using Process.Start("INVITE LINK") as that was the code I found in the vast majority of results I got when I Googled the issue. However, it would seem that this doesn't work in Visual Studio 2019, as evidenced by the error I get. Either that, or I've overlooked something (which wouldn't be the first time, as I kind of have a habit of not reading things properly).
I'm sure I've managed it before, but I can't for the life of me remember how it was done; I'm asking here in the hope that someone can push me in the right direction. Thanks in advance.

Taken from an answer in c#,
using System.Diagnostics;
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "https://discord.gg/(invite code goes here)";
myProcess.Start();
It's not much different in vb
Imports System.Diagnostics
Dim myProcess = New Process()
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.FileName = "https://discord.gg/(invite code goes here)"
myProcess.Start()

Related

WinAppDriver - How to set up session in VB.NET for testing Classic Windows Application

Since Microsoft has said that Visual Studio 2019 is the last to include Coded UI, I am trying to move our Windows Desktop Application automation solution their recommended replacement, WinAppDriver.
I am having trouble getting the session going with the examples I have found online. Many C# examples, but I have not found any VB.NET examples.
The C# online Notepad example starts like:
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", #"C:\Windows\System32\notepad.exe");
NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
I have successfully (I think) converted the first two lines to VB.NET like this:
Dim appCapabilities As DesiredCapabilities = New DesiredCapabilities()
appCapabilities.SetCapability("app", "C:\Windows\System32\notepad.exe")
I need to get the third line from the C# example code above converted to VB.NET so that we can hopefully get WinAppDriver working for our existing CodedUI automation solution.
It's not clear where NotepadSession was declared, so you may need to change this some, depending on what kind of scope you need for the variable:
Dim NotepadSession As New WindowsDriver(Of WindowsElement)(New Uri("http://127.0.0.1:4723"), appCapabilities)

VBA / .Net download files from password protected website via Windows Security

I have a SharePoint test website (Azure SharePoint farm) which contains several image files and some document templates. I want to download the images to my local drive. I anticipate looping through a list of URLs, e.g. http://mySharePointSite/Sites/Images/Image01.png and downloading each in turn. I've tried URLDownloadToFile which works great if I put the images on a regular website but I'm unable to get past Windows Security with this approach.
I had a go at creating an InternetExplorer.Application Object (late binding) and can view my images but am unable to download them. Was trying ieApp.ExecWB but this throws a Run Time Error that seems insurmountable.
I've also tried WinHTTP.WinHTTPrequest.5.1 (StackOverflow 22051960) but, while that looked promising it returned a short string "???????" instead of an image.
I'm really hoping for a VBA solution and am wondering if Impersonate User might provide options, or if there are other options (excluding using SendKeys). Sadly I'm pushing the limits of my VBA knowledge and could really use some guidance.
Is it possible to download from share point from VBA?
If so how, am I missing something simple?
I can paste code, but really I'm not sure I have anything worth sharing. If this is not possible or unreliable in VBA then would be possible with VB.Net (my next steepest learning curve)?
Hope this helps someone. I ended up using Visual Studio to create a dll in VB.Net that I can call from VBA. VB.Net dll requires references to microsoft.sharepoint.client
And the VBA code requires a reference to the resulting dll.
Imports Microsoft.SharePoint.Client
Module Module1
Sub Main()
Dim myContext As Microsoft.SharePoint.Client.ClientContext
myContext = New ClientContext("http://TestSP-a.cloudapp.net/sites/Images/")
Dim myCredentials As New System.Net.NetworkCredential
'' I'm accessing a website from the outside so there
'' are no credentials on my PC. If on the same NW I
'' assume I can use the line below instead of the
'' 3 lines that follow.
'myCredentials = System.Net.CredentialCache.DefaultNetworkCredentials
myCredentials.UserName = "UserNameForSharePoint"
myCredentials.Password = "PassWordForSharePoint"
myCredentials.Domain = "" ' <-- Leave Blank
Dim mySiteSP As New Uri("http://TestSP-a.cloudapp.net/sites/Images/Image1.png")
Dim myTemp As String = "C:\temp\test.png"
My.Computer.Network.DownloadFile(mySiteSP, myTemp, myCredentials, True, 600000I, False)
End Sub
End Module

AWS error "EC2Client is 'friend'" - bug in SDK for .NET?

I am trying to write a program in vb.net which uses AWS's Web Service to change the permissions for a security group in EC2.
I have installed the AWS SDK for .Net.
I found an example of how to do this in C# on http://awsdocs.s3.amazonaws.com/sdk-net/latest/aws-sdk-net-dg.pdf (page 39).
I have managed to translate the code into vb, but I am getting an error concerning the 2nd of the following two lines:
Dim ec2Client As New AmazonEC2Client(credentials, config)
Dim ingressResponse As AuthorizeSecurityGroupIngressResponse = ec2Client.AuthorizeSecurityGroupIngress(ingressRequest)
The error Visual Studio gives for this second line is:
Amazon.EC2.AmazonEC2Client.Friend Function AuthorizeSecurityGroupIngress(request As Amazon.EC2.Model.AuthorizeSecurityGroupIngressRequest) As Amazon.EC2.Model.AuthorizeSecurityGroupIngressResponse' is not accessible in this context because it is 'Friend'.
I have read everything I can find on the topic and have posted this on the AWS forum but nothing is helping me.
All other AWS references within Visual Studio seem fine, so I am beginning to wonder whether this is a bug in the SDK for .NET.
I am desperate for help as I cannot call the AWS web-service without this line.
Any suggestions would be greatly appreciated!
In the line:
Dim ingressResponse As AuthorizeSecurityGroupIngressResponse() = ec2Client.AuthorizeSecurityGroupIngress(ingressRequest)
You are storing the response of AuthorizeSecurityGroupIngress in a function() rather than a variable.
Change AuthorizeSecurityGroupIngressResponse() into AuthorizeSecurityGroupIngressResponse.
I think that it is a bug; however, I have found a way to get around it by using AuthorizeSecurityGroupIngressAsync instead of AuthorizeSecurityGroupIngress:
Dim ec2Client As New AmazonEC2Client(credentials, config)
Dim ingressResponse As System.Threading.Tasks.Task(Of AuthorizeSecurityGroupIngressResponse) = ec2Client.AuthorizeSecurityGroupIngressAsync(ingressRequest)

Sending Multi-threaded SendEmail request returns General Mapi Failure

I'm using the MAPI code by Dave Brooks.
I am attempting to programatically send out a Crystal Report that is generated.
When I run through the code without threading everything runs fine. The problem is when I use threading I get the return error "General MAPI failure [2]".
I have never used threading before and understand that there are dangers involved. Can anyone provide any insight into this issue? NOTE: I've removed exception handling to make the code clearer.
Private Sub RunReport()
SetParameters()
SaveReportFile()
Dim operation As New ThreadStart(AddressOf SendEmail)
Dim theThread As New Thread(operation)
theThread.Start()
End Sub
Public Sub SendEmail()
Dim m As MAPI
m = New MAPI()
Dim email As String
For Each email In emailAddress
m.AddRecipientBCC(email)
Next email
m.AddAttachment(#"c:\temp\report.pdf")
m.SendMailPopup("Requested Report", "")
End Sub
A very late answer, but thought I'd add it anyway as I just encountered this and couldn't find an answer elsewhere.
You need to set your thread's appartment state to STA before it is started using:
theThread.SetApartmentState(ApartmentState.STA);
Note that threads from the threadpool (e.g. used by BackgroundWorker component) are MTA.
I encountered this same error (General MAPI failure [2]) and came across this solution early in my debugging; however, the cause for my error was due to running my application as administrator while outlook was running as my user. I had a hard time finding the cause of my error so hopefully this will help someone on the same search as me.
If the above answer doesn't solve your problem, try running your application without elevated privileges if possible or find a way to call MAPI using user impersonation.

Track installs of software

Despite my lack of coding knowledge I managed to write a small little app in VB net that a lot of people are now using. Since I made it for free I have no way of knowing how popular it really is and was thinking I could make it ping some sort of online stat counter so I could figure out if I should port it to other languages. Any idea of how I could ping a url via vb without actually opening a window or asking to receive any data? When I google a lot of terms for this I end up with examples with 50+ lines of code for what I would think should only take one line or so, similar to opening an IE window.
Side Note: Would of course fully inform all users this was happening.
Just a sidenote: You should inform your users that you are doing this (or not do it at all) for privacy concerns. Even if you aren't collecting any personal data it can be considered a privacy problem. For example, when programs collect usage information, they almost always have a box in the installation process asking if the user wants to participate in an "anonymous usage survey" or something similar. What if you just tracked downloads?
Might be easier to track downloads (assuming people are getting this via HTTP) instead of installs. Otherwise, add a "register now?" feature.
You could use something simple in the client app like
Sub PingServer(Server As String, Port As Integer)
Dim Temp As New System.Net.Sockets();
Temp.Connect(Server, Port)
Temp.Close()
End Sub
Get your webserver to listen on a particular port and count connections.
Also, you really shouldn't do this without the user's knowledge, so as others have said, it would be better to count downloads, or implement a registration feature.
I assume you are making this available via a website. So you could just ask people to give you their email address in order to get the download link for the installer. Then you can track how many people add themselves to your email list each month/week/etc. It also means you can email them all when you make a new release so that they can keep up to date with the latest and greatest.
Note: Always ensure they have an unsubscribe link at the end of each email you send them.
The guys over at vbdotnetheaven.com have a simple example using the WebClient, WebRequest and HttpWebRequest classes. Here is their WebClient class example:
Imports System
Imports System.IO
Imports System.Net
Module Module1
Sub Main()
' Address of URL
Dim URL As String = http://www.c-sharpcorner.com/default.asp
' Get HTML data
Dim client As WebClient = New WebClient()
Dim data As Stream = client.OpenRead(URL)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = ""
str = reader.ReadLine()
Do While str.Length > 0
Console.WriteLine(str)
str = reader.ReadLine()
Loop
End Sub
End Module
.NET? Create an ASMX Web Service and set it up on your web site. Then add the service reference to your app.
EDIT/CLARIFICATION: Your Web Service can then store passed data into a database, instead of relying on Web Logs: Installation Id, Install Date, Number of times run, etc.