Member Avatar for Member #940193

i want to know that how can we download file in visual basic silently without notifying users .... its my application update , also how could we create thread in visual basic so that this thread always check for updates and downloads silently

Dani AI

Generated

Silent updates can be OK when users or IT have opted in, but is right about the security angle: never ship code that downloads without prior consent. In enterprise rollouts like described, consent is given at install time or by policy, so the updater runs quietly in the background.

@nova37, you are using VS2012 (VB.NET), but your snippet is a VB6-style declare. In .NET you do not need urlmon; use the framework and run it off the UI thread. Also wire the actual form Load event. This minimal pattern checks a version file and downloads an update silently with no UI:

Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    Await CheckForUpdatesAsync()
End Sub

Private Async Function CheckForUpdatesAsync() As Task
    Dim manifest As String = "https://server/app/version.txt"
    Dim pkg As String = "https://server/app/update.zip"
    Dim dest As String = IO.Path.Combine(IO.Path.GetTempPath(), "update.zip")
    Using wc As New Net.WebClient()
        Dim latest As String = (Await wc.DownloadStringTaskAsync(manifest)).Trim()
        If New Version(latest) > New Version(Application.ProductVersion) Then
            Await wc.DownloadFileTaskAsync(pkg, dest) 'silent download
            'verify hash/signature, then apply on next start
        End If
    End Using
End Function

Tips:

  • Keep the updater separate from the main EXE (a small launcher), as suggested, so you can replace files while the app is stopped.
  • Compare file versions, download to a temp file, verify a hash/signature, then swap on restart.
  • If you really are targeting VB6, the URLDownloadToFile declare must return a value (HRESULT) and you should check that code; in .NET prefer the approach above.

Recommended Answers

All 7 Replies

You can't download silently because that would violate computer security although there are probably ways to get around that. The only reason I can think of why you would even want to do that is if you are writing a virus or something like that.

I used to do this all the time for corporate apps. It was critical that the users ran the current version of the software so the apps had a front end that would compare the date/time stamps of all installed modules to those on the server. Any new modules were copied to the user's PC before the app was actually loaded. I used a common launcher.exe that took three parameters

  1. local app folder
  2. server app folder
  3. local executable to run after updating

I'll bet your programs did not do it siently without user knowledge.

The browser you are using is siliently downloading stuff all the time. It is a matter of do you trust the program.

I use a third party Firewall to block everything unless I grant it permission. However, once you grant a program access to the internet, there is very little you can do about controlling what it downloads. That is where a good anti-virus program comes in that scans internet traffic for the obvious stuff.

Granted, polite programs ask for permission. i.e. Check for Updates, download updates automatically, etc.

To the OP: see: http://www.daniweb.com/software-development/vbnet/threads/441772/silent-browser-download

Edit: I forgot I was in the VB6 forum not VB.Net. Not used to seeing AD or Jim here and I got confused.

Instead see: http://www.ex-designz.net/apidetail.asp?api_id=498 for using URLDownloadToFile.

I'll bet your programs did not do it siently without user knowledge.

Actually, it did. And that was at the users' request. They didn't care about updates or being informed about what version they were using. All they cared about was that the software worked. When you are an operator controlling many billions of dollars of equipment and ensuring that power gets delivered reliably to a million local customers and to neighbouring provinces and states you have better things to do than acknowledge message boxes that do nothing more than tell you that everything is working. It's when things aren't working that you need the alerts.

Member Avatar for Member #940193

Am using visual studio 2012 for my vb project i tried above links
current code is but not working

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long)

    Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
        Dim lngRetVal As Long
        lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
        If lngRetVal = 0 Then DownloadFile = True
        Label4.Text = lngRetVal
    End Function
    Private Sub Form_Load()
         DownloadFile("http://www.forex-tribe.com/img/final1.png", "c:\\final1.png")
    End Sub

I agree with Jim on this. Also making use of silent downloads. Obviously the necesarry approval was obtained when a new installation was made to a client. After that it is our responsibility to see that the app runs 100%.

, agreed. All the installer has to do is to ensure that your app is cleared through all AV and FW's, then compare the versions and download when needed. It IS nice to see Jim and AD in here as well. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.