Automatically install new version from the internet

Does any one have some source code that I can put in my application that will query a web site that may contain a newer version of my software and ask the user if he would like to upgrade now?
Ant031898Asked:
Who is Participating?
 
abancroftConnect With a Mentor Commented:
No can do - it's company confidential.

But I can tell you how it's done and give some code examples...and you can ask specific questions.

Also, this uses FTP - not HTTP.

Algorithm:
1. At the very beginning of the app startup (first few lines of OnInitInstance) a thread is spawned that checks the company FTP site.
2. The thread creates a URL that uniquely identifies a file on the FTP server.
3. The thread downloads the file from the URL.
4. File contains 2 lines:
    1st is the application latest version number
    2nd is a URL where the patch/install is located
5. The thread writes the info from 7 to the registry.
6. At the end of app startup (end of OnInitInstance), the app checks the version number written by the thread. If it's later than the current one, it offers to download.

To create the thread:
1. Declare a CWinThread* object in your app (e.g. CWinThread* m_pThread);
2. Start the thread:
 m_pThread = AfxBeginThread(pfnThreadProc, NULL, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
 m_pThread->m_bAutoDelete = FALSE;
 m_pThread->ResumeThread();
3. To clean up the thread in ExitInstance():
 delete m_pThread;
 m_pThread = NULL;

The guts of the thread function:

  try
  {            
   CInternetSession cInetSess("Version Check");            // The internet session.
   CFtpConnection* pConn = NULL;      // The FTP connection to download the file

   // Open the FTP connection
   try
   {
    pConn = cInetSess.GetFtpConnection("your server name & path");
   }
   catch(CInternetException* pEx)
   {
    pEx->Delete();
    pConn=NULL;
   }

   if (pConn!=NULL)
   {
    CInternetFile *pFile=NULL;
    try
    {
     pFile = pConn->OpenFile("Your filename");
    }
    catch(CInternetException* pEx)
    {
     pFile=NULL;
     pEx->Delete();
    }

    // Parse the file.
    if (pFile!=NULL)
    {
     // I'll leave the parsing up to you....

     pFile->Close();
     delete pFile;
    }

    pConn->Close();
    delete pConn;
   }
   cInetSess.Close();
  }
  catch(CInternetException* pEx)
  {
   pEx->Delete();
  }
  catch(...)
  {
  }
 }
0
 
abancroftCommented:
I have some code for MFC - will that do?
0
 
arikkaCommented:
pls send it me on arikka@amdocs.com
I'll apreciate it very much. Tnx...
0
 
Ant031898Author Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.