Writing a small Windows Application (Programming Thread) - Page 1
Forum section: electronics / general

author: Unknown
author_rank: Unknown
timestamp: March 11, 2015, 07:04:49 am
content: I want to write a small Windows application which I can run as a standalone EXE (without installation). Essentially all I need it to do is periodically check a webpage (or multiple sites) for changes and if it's updated, play a WAV file and display a small alert on top of all other windows alerting the user there are changes. The visual alert ideally should be something unobtrusive that just sits in the corner until it's dismissed (rather than a dialog box that pops up and steals focus).I'm not a programmer at all and the last time I touched Visual Basic was in high school. Any suggestions on some software or language I can use to achieve this? I'm pretty out of touch with software development.

author: andersm
author_rank: Super Contributor
timestamp: March 11, 2015, 08:32:59 am
content: I would recommend one of the .NET languages (which includes Visual Basic). It means you do need to have the .NET framework installed, but implementing all the functionality without a rich framework will be a lot of work.

author: Fred27
author_rank: Unknown
timestamp: March 11, 2015, 09:01:59 am
content: Grab a free version of Visual Studio (was Express, but now Community Edition for the latest version I think). Great IDE, lots of help about. I'd suggest C# over VB, but either will do.

author: PA0PBZ
author_rank: Super Contributor
timestamp: March 11, 2015, 11:21:50 am
content: There is an extension for Chrome that does exactly that, look for page monitor in the chrome store.

author: codeboy2k
author_rank: Super Contributor
timestamp: March 11, 2015, 11:50:54 am
content: If all you are looking for is changes on websites.. I suggest you steer clear of VB, C#, .NET and all that. Yes, it will get you a standalone EXE, but you will also have to write SOOOOOO much more code to make it work for you, and you will be tearing your hair out.If you started with VB in high school and you say you are not much of a programmer, then I would recommend python. It's very easy to learn, and there are many online tutorials and many more available libraries to do exactly what you want to do.This one line in python scrapes a web page: (note: spelling htttp incorrectly on purpose, by my choice.. there is a bug in the forum, if you put code with http links, it rewrites them,EVEN INSIDE THE CODE BLOCK THAT IT SHOULD NOT TOUCH!!. So I know its http but I put htttp to trip up the forum parser.Code: (python)page = requests.get('htttp://example.com').textThe complete python program to load the webpage and save it to a disk file is:Code: (python)import requestspage = requests.get('htttp://example.com').textfd = open('/tmp/thepage.html', 'w')fd.write(page)fd.close()If you need to examine the tree structure of the page, to look for specific changes on the page, then there is a library called BeautifulSoup that will help you do that very easily.You can write a loop around this program above to scrape the same page periodically and compare it to the saved page on disk. If it's different, you can raise a desktop notice to let the user know. There are libraries to help you do that too, such as Growl for windows (http://www.growlforwindows.com/gfw/) and growl transport for python GNTP (https://github.com/kfdm/gntp/)The following 4 lines of additional code added to the above python code would pop-up a screen notification.Code: (python)import logginglogging.basicConfig(level=logging.INFO)import gntp.notifiergntp.notifier.mini("The webpage example.com has changed!")The point of me writing this code is to show you how dead-simple it can be in python. Don't install some massive IDE and start writing a windows EXE to do what you want to do.PS: I realize you said no installer. All the above requires an installer, to install python and the library you need and the Growl Notifier.So you can finish it in 1 day with an installer, or attempt it 1 month or more with a standalone EXE written in .NET, as you try to write and learn at the same time.

author: ElektroQuark
author_rank: Unknown
timestamp: March 11, 2015, 12:48:34 pm
content: Try wget.

author: Mechanical Menace
author_rank: Super Contributor
timestamp: March 11, 2015, 12:53:07 pm
content: Quote from: codeboy2k on March 11, 2015, 11:50:54 am+1That plus thishttps://github.com/pyinstaller/pyinstaller/wikicould be the perfect solution for you if you really need the standalone exe.

author: Wilksey
author_rank: Super Contributor
timestamp: March 11, 2015, 12:59:11 pm
content: Personally i'd use C#.You can do it in C/C++ but it will take a much longer to write.Your best bet, if you get confused, and you probably will after reading everyones responses is to contract it out, there was a website where you could do this, Rent A Coder I think it was called, people asking for bids on work.The task itself is insignificant and can be done quite easily for someone who has time / progrramming knowledge.

author: codeboy2k
author_rank: Super Contributor
timestamp: March 11, 2015, 05:20:53 pm
content: Quote from: EdoNork on March 11, 2015, 12:48:34 pmYep, you can shell script it with wget. My first choice on Linux would be that way, but scripts on Windows suckPython seemed to me to be the better "scripting" language for this on Windows.

author: magetoo
author_rank: Frequent Contributor
timestamp: March 11, 2015, 07:33:20 pm
content: Do the sites come with RSS feeds, by any chance?If so, IFTTT could be an option, and it is simpler than writing your own tool. I put together a small "recipe" to send me an email whenever a feed updated in just a couple of minutes. It's free and pretty self explanatory.Yeah, being purely a web based service it won't be able to reach into your computer and play an audio file, but there are "actions" available that can do other useful things like send notifications to phones or talk to various Internet-of-Things hardware, so there might be something there that works for you.If the thing you want to monitor doesn't have an RSS feed, I'm not sure how one would do it. (Maybe it would be possible to use Yahoo Pipes, it can pull data from the web and generate a RSS feed from anything... but it's probably not worth the trouble.)

author: DavidDLC
author_rank: Frequent Contributor
timestamp: March 11, 2015, 07:45:06 pm
content: When you have it done, share with me, I just missed 3 free office chairs in perfect condition at CraiglistDavid.

author: Stonent
author_rank: Super Contributor
timestamp: March 11, 2015, 07:49:51 pm
content: Quote from: Wilksey on March 11, 2015, 12:59:11 pmC# or PowerShell.For C#, compiling with .NET 2 or 3 will work just about on any computer.PowerShell can do almost anything C# can do since it's also .NET based. The difference being you have to invoke the .NET stuff manually.I wrote a digital signage application at work in PowerShell for an assembly line. It has 2 timer threads that query a database one thread every 15 seconds, the other every 60 seconds. The 15 second interval is just an overall system status (Running, Unplanned Stop, Planned Stop), the 60 second thread queries the stats. How many widgets completed, in progress, how many have passed through a specific production point, down time per line etc.The script was a proof of concept / challenge on my own time that I could write a replacement for our licensed digital signage application myself in C#, but was sort of shot down a bit when I showed the non-functional display mockup to my boss and he said that deploying compiled code makes management nervous. So I about gave up on it, until I figured out how to reference WPF in PowerShell. Now the only compiled code is the .NET framework itself and nothing I wrote.Basically I taught myself powershell during the Christmas break this past year.

author: Prime73
author_rank: Regular Contributor
timestamp: March 11, 2015, 08:05:24 pm
content: have considered a web browser extension?something like this one:https://chrome.google.com/webstore/detail/page-monitor/pemhgklkefakciniebenbfclihhmmfcd?hl=enQuote from: Halon on March 11, 2015, 07:04:49 am

author: nctnico
author_rank: Super Contributor
timestamp: March 11, 2015, 09:29:38 pm
content: Quote from: Wilksey on March 11, 2015, 12:59:11 pmNot really. It's just a matter of using the right framework. With WxWidgets you can easily create a static linked exe file which will work standalone on about any version of Windows.

author: codeboy2k
author_rank: Super Contributor
timestamp: March 11, 2015, 10:53:24 pm
content: Quote from: magetoo on March 11, 2015, 07:33:20 pmOh, yes. +1.I forgot about IFTTT but that's also a good choice, worthy of a look. Won't be able to do the desktop notifications directly, but email or IM , or TWILIO SMS as an output notification might be an option here.https://ifttt.com/wtf

author: Unknown
author_rank: Unknown
timestamp: March 11, 2015, 10:57:37 pm
content: Thanks for all the great suggestions guys.Unfortunately the site is part of our intranet and doesn't have RSS. I also don't have the option of installing Chrome plugins for security reasons. If I write the application myself, I can easily have it checked and cleared so I can bring it to work.

author: Galenbo
author_rank: Super Contributor
timestamp: March 15, 2015, 06:40:55 pm
content: Althroug I haven't used it for a while, I played around some time wit this:http://en.wikipedia.org/wiki/Processing_%28programming_language%29Seems a lightweight install, producing lightweight programs.No idea if it can produce .exe without extras.

author: PA0PBZ
author_rank: Super Contributor
timestamp: March 15, 2015, 08:24:18 pm
content: To get a page in HTML with visual basic is not that hard:Code:Imports System.NetImports System.IOFunction getHTML(ByVal Address As String) As StringDim wREQ As WebRequestDim wRSP As WebResponseDim Reader As StreamReaderwREQ = WebRequest.Create(Address)wRSP = wREQ.GetResponseReader = New StreamReader(wRSP.GetResponseStream)Return Reader.ReadToEndReader.Close()End FunctionCall the function like this:String1 = getHTML("http://www.google.com")then use a timer to call it again and compare the result with String1. If there is a difference do whatever alert you want.Or if you want toplay with ittest it put a button and a textbox on your form andCode:Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.ClickTextBox1.Text = getHTML("http://www.google.com")End Sub

author: Stonent
author_rank: Super Contributor
timestamp: March 16, 2015, 12:56:54 am
content: Quote from: PA0PBZ on March 15, 2015, 08:24:18 pmAnd just for fun because C# and VB.NET almost word for word translate, I translated it.Code:using System.Net;using System.IO;namespace httpget{class Program{static void Main(string[] args){// this will just dump raw data to the screenSystem.Console.WriteLine(getHTML("http://www.google.com"));System.Console.ReadLine();// or you could do// string string1 = getHTML("http://www.google.com");}static string getHTML(string Address){WebRequest wREQ;WebResponse wRSP;wREQ = WebRequest.Create(Address);wRSP = wREQ.GetResponse();StreamReader Reader = new StreamReader(wRSP.GetResponseStream());try{return Reader.ReadToEnd();}finally{Reader.Close();}}}}

author: Stonent
author_rank: Super Contributor
timestamp: March 16, 2015, 01:03:04 am
content: But wait! There's more. No need to compile anything, just use PowerShell!Code:# // first argument is mapped to $urlparam($url)# // create a request[Net.HttpWebRequest] $req = [Net.WebRequest]::create($url)$req.Method = "GET"$req.Timeout = 600000 # = 10 minutes# // Set if you need a username/password to access the resource#$req.Credentials = New-Object Net.NetworkCredential("username", "password");[Net.HttpWebResponse] $result = $req.GetResponse()[IO.Stream] $stream = $result.GetResponseStream()[IO.StreamReader] $reader = New-Object IO.StreamReader($stream) $output = $reader.readToEnd()$stream.flush()$stream.close()# // return the text of the web pageWrite-Host $outputUsage:powershell script.ps1http://yoururl.com

author: miguelvp
author_rank: Super Contributor
timestamp: March 16, 2015, 02:24:23 am
content: PowerShell is da bomb.There are like 8 hours of training at Microsoft, I did a couple of hours but it's in my list of things to continuehttp://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start

author: Stonent
author_rank: Super Contributor
timestamp: March 16, 2015, 03:06:23 am
content: Quote from: miguelvp on March 16, 2015, 02:24:23 amI'd say 90%+ of things you can do in C# you can do in PowerShell, even GUI stuff.