2009-08-19 98 views
1

我有這個Windows移動應用程序。如何殺死我的手機應用程序?

我想啓動一個updater.exe來更新我的移動應用程序。但是,在更新程序啓動之前,我需要停止移動應用程序。我該如何實現這一目標?

回答

3

我做什麼,如果你推出從裏面自己更新應用程序,與Process.Start("\Path\To\Updater.exe");執行更新,然後立即關閉主要的應用程序(與this.Close();Application.Quit();。這應該只是罰款。

殺從更新內部的主應用程序,你將不得不使用的p/Invoke和系統調用的方法來找到並殺死的主要應用它最終應該是這樣的(未經測試):

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); 
    } 
}

然後用CloseWindow.Close("My Application Title");調用它。

+0

謝謝,這正是我一直在尋找的! – pdiddy 2009-08-20 13:06:05

相關問題