2009-08-19 53 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