Solved

Code for "click here to check for updates"

Posted on 2002-03-21
10
396 Views
Last Modified: 2008-02-01
In many of the programs that I have, I get a window popping up periodically asking if I want to check the web for updates.
How can I add to my VB6 code so that my program will check my website for updates?
Prof Weissman
0
Comment
Question by:mathprof
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6887562
every time you program runs, check date against some value stored in some place (maybe registry) and if difference is, i.e. 30 days, pop a window with a hyperlink to your website.
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6890329
Hi!

To check for updates, you can use the Inet control to download a file from your website.  When the file is downloaded, it'll check the contents of the file (eg. Code, Date, Serial Number, version number... etc.)  If the file indicates that there's a new update, then download the update from your site if the user wants it : )

Here's a file over the net to help you to do that:

Download...
http://www.vb-helper.com/HowTo/ftp.zip
Description: Upload and download files using FTP (4K)

or

Download...
http://www.vb-helper.com/HowTo/inetgetchunk.zip
Description: Use the Internet Transfer Control's Execute method and GetChunk to download a file (3K)


Oh yes, you'll have to check for the date when your proggy runs, like what Richie_Simonetti has mentioned : )

That's it!

glass cookie : )
0
 

Author Comment

by:mathprof
ID: 6892643
Glass Cookie,
I downloaded both VB projects.
The documentation is poor. Could you please explain what I am inputting in each VB project, and what is supposed to happen. The first asks for about 5 or 6 items, the second project just one URL.
Prof Weissman
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6893155
Hi!

Here's the documented version:

For the textboxes:

txtHost - you'll have to specify the ftp site to uplodad/download to.

txtUserName - specify the username

txtUserName - specify the password

txtLocalFile - the filepath on your current hard disk

txtRemoteFile - the filename to be on the site that you're uploading/downloading.

I'll now comment on the coding part of it:




Option Explicit

Private m_GettingDir As Boolean

'This sub merely adds text ovr a textbox by the name, txtResults
Private Sub AddMessage(ByVal msg As String)
    'Add a line of string to the textbox
    txtResults.Text = txtResults.Text & vbCrLf & msg
    'Set position to the last character
    txtResults.SelStart = Len(txtResults.Text)
End Sub

Private Sub cmdDownload_Click()
Dim host_name As String

    'Disbale the button so that the user wouldn't double-click it
    Enabled = False
    'Change the mouse pointer to indicate it's working
    MousePointer = vbHourglass
    'Changes of a caption
    txtResults.Text = "Working"
    'Changing of position of pointer in the textbox
    txtResults.SelStart = Len(txtResults.Text)
    'Return process time to the OS to finish other jobs.
    DoEvents

    ' You must set the URL before the user name and
    ' password. Otherwise the control cannot verify
    ' the user name and password and you get the error:
    '       Unable to connect to remote host
    'Add the host name to the string variable
    host_name = txtHost.Text
    'Add the string "ftp://" if it is not on the host name
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name
    'Set the host name on the inet control
    inetFTP.URL = host_name

    'Set user ID and password to control
    inetFTP.UserName = txtUserName.Text
    inetFTP.Password = txtPassword.Text

    'Using the Get command to download a file from the net/site
    inetFTP.Execute , "Get " & txtRemoteFile.Text & " " & txtLocalFile.Text

End Sub

Private Sub cmdUpload_Click()
Dim host_name As String

    'Similar to the comment that I've added above :)
    Enabled = False
    MousePointer = vbHourglass
    txtResults.Text = "Working"
    txtResults.SelStart = Len(txtResults.Text)
    DoEvents

    ' You must set the URL before the user name and
    ' password. Otherwise the control cannot verify
    ' the user name and password and you get the error:
    '
    '       Unable to connect to remote host
    'Add "ftp://" to the host name if it's not specified
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name
    inetFTP.URL = host_name

    'Setting of username and passowrd
    inetFTP.UserName = txtUserName.Text
    inetFTP.Password = txtPassword.Text

    'Use the "put" command to upload the file to the site
    inetFTP.Execute , "Put " & txtLocalFile.Text & " " & txtRemoteFile.Text

'    m_GettingDir = True
'    inetFTP.Execute , "Dir"
End Sub

Private Sub inetFTP_StateChanged(ByVal State As Integer)
    Select Case State
        Case icError
        'Prints the error msg to the textbox if there's an error+it's description
            AddMessage "Error: " & _
                "    " & inetFTP.ResponseCode & vbCrLf & _
                "    " & inetFTP.ResponseInfo
        Case icNone
            AddMessage "None"
        Case icConnecting
            AddMessage "Connecting"
        Case icConnected
            AddMessage "Connected"
        Case icDisconnecting
            AddMessage "Disconnecting"
        Case icDisconnected
            AddMessage "Disconnected"
        Case icRequestSent
            AddMessage "Request Sent"
        Case icRequesting
            AddMessage "Requesting"
        Case icReceivingResponse
            AddMessage "Receiving Response"
        Case icRequestSent
            AddMessage "Request Sent"
        Case icResponseReceived
            AddMessage "Response Received"
        Case icResolvingHost
            AddMessage "Resolving Host"
        Case icHostResolved
            AddMessage "Host Resolved"

        Case icResponseCompleted
            AddMessage inetFTP.ResponseInfo

            If m_GettingDir Then
                Dim txt As String
                Dim chunk As Variant

                m_GettingDir = False

                ' Get the first chunk.
                'Get the data from the download
                chunk = inetFTP.GetChunk(1024, icString)
                DoEvents

                'Keep getting data until there's no more data to get
                'The getchunk method of the control gets data at 1024 bytes each time.  It'll be a null if there's no more data to be recieved.
                Do While Len(chunk) > 0
                    txt = txt & chunk
                    chunk = inetFTP.GetChunk(1024, icString)
                    DoEvents
                Loop

                'Prints something to the textbox
                AddMessage "----------"
                AddMessage txt
            End If

       Case Else
            AddMessage "State = " & Format$(State)
    End Select

    'Enables the button and sets the mousepointer to normal.
    Enabled = True
    MousePointer = vbDefault
End Sub


Oh yes, something that you should take note when coming to the get and put commands when using the inet control.  THe position of the strings of the filepath of your HDisk and filename to be on that site is swapped when using these 2 commands:

inetFTP.Execute , "Put " & txtLocalFile.Text & " " & txtRemoteFile.Text
inetFTP.Execute , "Get " & txtRemoteFile.Text & " " & txtLocalFile.Text

Get the idea?  I suppose so : )

That's it!

glass cookie : )

PS. Good luck in your programming!
0
 

Author Comment

by:mathprof
ID: 6895238
Hi Glass Cookie,
Where in the code does it 'check for the contents of the file on the server"? Specifically, the date of the file on the server.
Mathprof
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6895692
Hi!

No where in the code does the above example do that.  Well, if you're doing that, here's a file for you over the net to take a look at:

Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=21186&strZipAccessCode=ODE%5F211864422
Description: Nearly done Ftp aplication made with Wininet.bas (Wininet.dll). It (multi)downloads, (multi)uploads files, creates / removes folders, renames files, has progress bars, time and transfer speed rate and many others more or less usefull windows and ftp functions.

Snapshot:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=21186&lngWId=1

That's it!

glass cookie : )
0
 
LVL 8

Accepted Solution

by:
glass_cookie earned 100 total points
ID: 6895704
Oops!  I hope I didn't misinteprete your question.  Maybe I did.

Anyway, just to answer your question:

Have a small text file over your site that contains a date of the latest update file.  Your VB app would then download that text file and red it.  Should the file contain a date that's later than the one that you store (proabbly in the registry or a settings file for your VB app), then download the main update file from your site.

Anyway, to answer the date question that you asked more specifically, here's another file:

Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=10403&strZipAccessCode=ODE%5F104031981
Description: This control download a given Url to a local file. You can stop the download process on any time and resume it later. With this control you can also get information, like filesize, last modification date and if the file exists, about an given url. This control doesn't use any ActiveX control. Code is completly written with WinInet Api.


Here's something more - probably closer to what you're trying to achieve:

Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=13413&strZipAccessCode=ODE%5F134134712
Description:   This code allows you to update your programs .EXE via the Internet automatically. The program checks a file on a web-server with the most recent version number in it, compares it to your version and then either downloads the new file or not depending on which one is more current. This process utilizes the INET control for the file transfers.

Snapshot:
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=13413&lngWId=1

That's it!

glass cookie : )
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6977116
It looks to me that you have been provided with what you need here, please accept a comment to convert the comment to the Accepted Answer to grade and close this.

Expert input appreciated on closing recommendations as to whom to award; it appears to me that glass_cookie should be granted these points.  If a point split is in order, please advise me.

Moondancer - EE Moderator
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6977207
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20102401.html
http://www.experts-exchange.com/questions/Q.20116302.html
http://www.experts-exchange.com/questions/Q.20130066.html
http://www.experts-exchange.com/questions/Q.20280137.html
http://www.experts-exchange.com/questions/Q.20290269.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20108488.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6978754
Thank you for returning and finalizing this.
Moondancer - EE Moderator
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now