110,533
社区成员
发帖
与我相关
我的任务
分享
#region 杀进程的相关方法
public const int PROCESS_ALL_ACCESS = 0x000F0000 | 0x00100000 | 0xFFF;
[DllImport("coredll.dll")]
public extern static int GetWindowThreadProcessId(IntPtr hWnd, ref int lpdwProcessId);
[DllImport("coredll.dll")]
public extern static IntPtr OpenProcess(int fdwAccess, int fInherit, int IDProcess);
[DllImport("coredll.dll")]
public extern static bool TerminateProcess(IntPtr hProcess, int uExitCode);
[DllImport("coredll.dll")]
public extern static bool CloseHandle(IntPtr hObject);
public static bool Kill(IntPtr window)
{
int processId = 0;
GetWindowThreadProcessId(window, ref processId);
IntPtr hProcess = IntPtr.Zero;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, processId);
if (hProcess.ToInt32() != 0)
{
if (TerminateProcess(hProcess, 1))
{
CloseHandle(hProcess);
return true;
}
else
{
CloseHandle(hProcess);
return false;
}
}
else
{
return false;
}
}
#endregion
[DllImport("CoreDll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//查找网络连接程序并关闭,这样才能更新
IntPtr CncmPDAAutoUpdate = Common.PublicMethods.FindWindow(null, "网络连接");
Common.PublicMethods.Kill(CncmPDAAutoUpdate);