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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
abancroftCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ant031898Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.