进程关闭与开启代码
来源:互联网 发布:淘宝海外买手现场 编辑:程序博客网 时间:2024/05/22 14:50
// communication.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "afx.h"
#include <windows.h>
#define EXE_INSTANCE 2
//int CloseExe(string strExeName);
//int RunExe(string strExeName);
int CloseExe(CString strExeName)
{
HANDLE hProcessHandel = NULL;
ULONG nProcessID = 0;
HWND hProcessHwnd = NULL;
hProcessHwnd = ::FindWindow(NULL, (LPCTSTR)strExeName);
if (NULL == hProcessHwnd)
{
return -1;
}
::GetWindowThreadProcessId(hProcessHwnd, &nProcessID);
hProcessHandel = ::OpenProcess(PROCESS_TERMINATE, FALSE, nProcessID);
return ::TerminateProcess(hProcessHandel, 4);
}
int RunExe(CString strExeName)
{
STARTUPINFO startupInfo={0};
startupInfo.cb=sizeof(STARTUPINFO);
startupInfo.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startupInfo.wShowWindow =SW_HIDE;
startupInfo.lpReserved=NULL;
startupInfo.lpReserved2=NULL;
startupInfo.lpDesktop=NULL;
PROCESS_INFORMATION proInfo;
::CreateProcess(NULL, strExeName.GetBuffer(), NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &proInfo);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
//weather the exe is one or two
if(1 == EXE_INSTANCE)
{
//if the second exe if running,close it
CloseExe("communication_two");
//run the first
RunExe("./communication_one.exe");
}
else if(2 == EXE_INSTANCE)
{
//if the first exe if running,close it
CloseExe("communication_one");
//run the second
RunExe("./communication_two.exe");
}
return 0;
}
- 进程关闭与开启代码
- MFC开启与关闭外部进程
- Qt 开启进程,查找进程,关闭进程
- 开启与关闭tomcat
- Mongodb开启与关闭
- Mongodb开启与关闭
- 开启与关闭硬件加速
- iptables开启与关闭
- Mongodb开启与关闭
- Mongodb开启与关闭
- Mongodb开启与关闭
- 推送关闭与开启
- Mongodb开启与关闭
- Mongodb开启与关闭
- Mongodb开启与关闭
- 防火墙开启与关闭
- Mongodb开启与关闭
- 【Android】代码开启/关闭GPS
- 网页中引用flash,flash引用xml路径问题
- The Facade Pattern
- Bitmap文件格式
- freetype安装
- 利用流光扫描的SQL弱密码 入侵远程机子
- 进程关闭与开启代码
- 获取 android 源代码, 并编译
- 几本适合新手的Android电子书(提供下载)
- VS2010技巧:如何在js文件中使用jQuery智能感知(转)
- 拦不住我的本地组策略
- GNU CC (GCC)与库文件的简要说明
- Lesson 1005 – 悬挂点
- alias definitation on bash and tcsh
- VC++内存泄漏定位