Track installs of software - vb.net

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.

Related

Is there a simple way to use VB.NET to read a SharePoint Online file without logging in?

I inherited a program written in VB.NET. I want to host the installer and documentation for the program in a SharePoint Online library. The SPO library allows View/Read-only access to "Everyone except external users" but it does not allow anonymous access. I want the program to check the SPO library for an updated version when it launches.
I envisioned a simple function like this:
Private Function getVersion() As String
Using client As New WebClient
getVersion = client.DownloadString("https://companyname.sharepoint.com/site/library/version.txt")
End Using
End Function
where version.txt contains nothing but the current version number.
However, this function throws an IOException stating that the connection was forcibly closed by the remote host. I think this is because the SPO site requires authentication.
I don't want to add a user login step solely for this one thing. This probably means an SPO site that requires authentication is not the ideal place for my version.txt file to reside, but I'm also trying to avoid solutions that require me to jump through hoops and involve others to get it to work. I'm the only developer for this program, so I'd like to be able to publish an update without having to wait for someone else to do something (like update a web server that I don't have access to).
Suggestions for a simple technique to achieve my goal?
In your Using block, before the line with DownloadString, set the Credentials of your WebClient:
Private Function getVersion() As String
Using client As New WebClient
client.Credentials = CredentialCache.DefaultCredentials
getVersion = client.DownloadString("https://companyname.sharepoint.com/site/library/version.txt")
End Using
End Function
The DefaultCredentials will be the credentials of the currently logged in Windows user.
See the docs on System.Net.WebClient.

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

how to hide http request using vb.net

I'm developing new app. This is app need to get information from my website so I use HTTP request using vb.net.
Sub Main()
'Address of URL
Dim URL As String = http://whatever.com
' 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
My problem is , I found an app called fiddler http://www.fiddler2.com/fiddler2/
This app could find all HTTP request that maked using my app , so this put my website at risk.
Is There any way how to hide HTTP request from been detected ????
I'm not familiar with this "fiddler" product, but just from reading the page that you reference, it is something that runs on the user's machine and monitors traffic between that computer and the Internet. I don't see how it would be even theoretically possible to prevent this. Signals are moving over wires leaving the user's computer. He presumably has physical access to his own computer. If nothing else, he could attach something to the cable coming out the back of the computer that monitors the signals moving over the wire.
You could encrypt messages so that it's difficult for the user to interpret what they mean, but you can't stop him from reading the message as it was sent.
I wonder, by the way, how it is a security problem for a user to know what messages are being sent from his own computer. Are you trying to hide what you are doing from the person using your program? Frankly, if I discovered that an application I have on my computer was trying to hide what it was doing from me, I would immediately delete it. Why would someone want to hide what he's doing to MY computer unless what he is doing is something sinister, trying to steal my personal data or some such?
Just to be slightly sarcastic, your question sounds a little like asking, When I visit a business associate, how can I prevent him from finding out out what I did in his office when he stepped out for a few minutes?
There is a way using the Proxy method just add this Code in the HTTP request:
Request.Proxy = New WebProxy()
cause how fiddler works it sets itself as the proxy using the above code it cannot set fiddler proxy and thats how you stop it from reading anything

How do you get an external computer's computer name in VB.Net?

This would be easier if I were able to have the external computer get its own name and just pass it to a web service as a variable, but I'm not able to do that right now. There are a variable number of computers from several different entities that regurarly access a web service on one of our servers. Changing only some VB.Net code on the server and nothing at all on any of those external computers, how would I be able to get their names programmatically in VB.Net? Thanks!
EDIT: Some of the answers look like they're designed to get the IP of either the server, the server's router, or something else along those lines. Maybe I'm just misreading the code or something, but I was talking about getting the names of client, external computers who try to access a webmethod on the server, using the webmethod's code to do so.
If there is no address translation and computers has DNS entries:
Dim ip As String = System.Web.HttpContext.Current.Request.UserHostAddress
Dim name as String = System.Net.Dns.GetHostEntry(ip).HostName()
System.Net.Dns.GetHostAddresses(My.Computer.Name)(5).ToString
Quick solution for getting external IP in VB.Net
Dim sIp As String
Dim webClient As System.Net.WebClient = New System.Net.WebClient()
sIp = webClient.DownloadString("http://lbb.ie/ip.php")
And that's it It is my own php file on my own server so go ahead :) Enjoy

Is it possible to host a webserver in VBA?

I want to host a web server and want to use VBA to do it. Is this possible? I'm just doing this to prove someone wrong and really want to make this program.
So is it possible to make a really simple web server (just listens for get requests)? Help would be very much appreciated.
EDIT
I'm trying something like this
Sub startServer()
Set wunsock = CreateObject("OSWINSCK.Winsock")
wunsock.LocalPort = 80
wunsock.Listen
End Sub
Sub wunsock_ConnectionRequest(ByVal requestID As Long)
If sockMain.State <> sckClosed Then
sockMain.Close
End If
sockMain.Accept requestID
End Sub
Private Sub wunsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
sockMain.GetData strData, vbString
txtStatus.Text = txtStatus.Text & _
strData & vbCrLf
End Sub
However it doesn't work?
Although this is a rather old question, I'd still like to mention that I built an Excel hosted REST webserver using plain VBA macros and some Winsock C calls, as proposed by Daniel A. White.
I added this as an answer instead of a comment, since it's built as a modular library, so you can adjust it to your needs, and others might need exactly this kind of library. It can serve both worksheets, basic files and also create custom hooks using an IWebController to listen on specific routes (which was mentioned by OP in a comment):
http://github.com/michaelneu/webxcel
To use it, you'll have to either import the classes/modules into your workbook, or let the build script create a new one for you. See Main.bas on how to start the server from within VBA.
http://www.ostrosoft.com/oswinsck.asp#inst
is a winsock type of library which can be used from VBA. It is possible to do what you are looking to do though is not the most efficient thing to do.
I do applaud your tenacity hope it works out for you.
I'm not sure I fully understand the question. Generally, you don't "host a web server", you host a web site.
But if you can do TCP sockets with VBA, then you can make an incredibly simple web server by following the HTTP standard protocol.
Edit: based on your comment, yes you can make a simple web server as long as you can open up a TCP socket.
Well, at the risk of violating the spirit of the question, you can always use VB's support for library functions and just create a library binding to one of a number of C-language web server options (such as http://www.acme.com/software/micro_httpd/, http://www.gnu.org/software/libmicrohttpd/ or http://code.google.com/p/mongoose/). You'd have to make DLLs out of the selected web server but that is reasonably easily done and this will work just fine in VBA.