views:

215

answers:

2

I have this windows mobile application.

I'd like to launch an updater.exe that will update my mobile app. But I need to stop my mobile app before the updater process launch .. how can I achieve this?

A: 

Settings => System => Memory => Running Programs => close.

JG
+2  A: 

What I've done is if you're launching the update application from inside your own, execute the updater with Process.Start("\Path\To\Updater.exe");, then immediately close the main app (with this.Close(); or Application.Quit();. It should work just fine.

To kill the main application from inside the updater, you'll have to use p/invoke and system call methods to find and kill the main application. It should end up something like this (untested):

class CloseWindow
{
    [DllImport("coredll.dll")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("coredll")]
    public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

    public const int WM_CLOSE = 0x0010;

    public static void Close(string windowName)
    {
        IntPtr hWnd = FindWindow(null, windowName);
        SendMessage(hWnd, WM_CLOSE, null, null);
    }
}

then call it with CloseWindow.Close("My Application Title");.

Andrew Koester
Thanks, it was exactly what I was looking for!
pdiddy