Many a times our applications (desktop applications) need automatic updations. The best recommended way is to have BITS API used. For very small applications, a quick console application that checks for updates, does updation and then starts the main application is a good trick.
Here is one such humble endeavor where a console application starts up and hides itself. The actual logic of updation is just a sleep for some time and then confirm back to the user that updates are complete. The launch of main (parent) application here is to just exit the console application.
using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms;
namespace ConsoleApplication1 { /// /// Summary description for Class1. /// class Class1 { [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
/// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { string strAppName = "\""+AppDomain.CurrentDomain.BaseDirectory+AppDomain.CurrentDomain.FriendlyName+"\""; IntPtr hWnd = FindWindow(null,strAppName); if (hWnd != IntPtr.Zero) { ShowWindow(hWnd,0); if (MessageBox.Show("There are updates. Proceed?","Update Confirm",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.No) { return; } else { ShowWindow(hWnd,0); Thread.Sleep(5000); MessageBox.Show("Updates are complete","System Update",MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); } } } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|