知道应用程序的路径和名称 该程序执行过程中 如何在VC程序中结束它

stoon123 2008-04-10 10:20:32
知道应用程序的路径和名称 该程序执行过程中 如何在VC程序中结束它
如何知道句柄 如何强制杀掉该程序或进程
谢谢
...全文
53 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wmouse 2008-04-11
如果::FindWindow,则返回值是CWnd*,因为调用的是CWnd::FindWindow。如果直接HWND m_hwndd=FindWindow,(去掉::),则调用的API,返回HWND。
回复
stoon123 2008-04-11
使用 HWND m_hwndd=::FindWindow(NULL,exefilename);
但调试时提示: CXX0030:Error:expression cannot be evaluated
这是怎么回事呢
回复
wmouse 2008-04-10

BOOL CProcessManager::FindProcess2Kill(LPCTSTR lpcExeFile, KillInfoCallback callback)
{
HANDLE hProcessSnap = NULL;
BOOL bRet = TRUE;
BOOL bFind = FALSE;
PROCESSENTRY32 pe32 = {0};
CString csInfo = _T("");

CString csTagName = lpcExeFile;
csTagName.MakeUpper();

// Take a snapshot of all processes in the system.

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hProcessSnap == INVALID_HANDLE_VALUE)
return FALSE;

// Fill in the size of the structure before using it.

pe32.dwSize = sizeof(PROCESSENTRY32);

// Walk the snapshot of the processes, and for each process,
// display information.

if (Process32First(hProcessSnap, &pe32))
{
DWORD dwPriorityClass;
BOOL bGotModule = FALSE;
MODULEENTRY32 me32 = {0};

do
{
CString csOrgName = pe32.szExeFile;
csOrgName.MakeUpper();

if (csTagName == csOrgName)
{
bFind = TRUE;
HANDLE hProcess;

// Get the actual priority class.
hProcess = OpenProcess (PROCESS_ALL_ACCESS,
FALSE, pe32.th32ProcessID);
dwPriorityClass = GetPriorityClass (hProcess);

DWORD dwExitCode = 0;
try
{
GetExitCodeProcess(hProcess, &dwExitCode);
BOOL bKill = TerminateProcess(hProcess, dwExitCode);
if (NULL != callback)
{

csInfo.Format(_T("%d - %s "), pe32.th32ProcessID, csOrgName);
if (bKill)
csInfo += "干掉了!";
else
csInfo += "杀不掉啊!";

callback(csInfo);
}
}
catch (CException* e)
{
char szError[MAX_PATH];
e->GetErrorMessage((LPTSTR)szError, MAX_PATH);
}

CloseHandle (hProcess);
}
}
while (Process32Next(hProcessSnap, &pe32));
}

if (!bFind)
{
csInfo = "没有找到进程";
csInfo += csTagName;
callback(csInfo);
}

// Do not forget to clean up the snapshot object.

CloseHandle (hProcessSnap);

return bRet;
}

BOOL FindProcessModule (DWORD dwPID, LPCTSTR lpcModuleName)
{
BOOL bRet = FALSE;
BOOL bFound = FALSE;
HANDLE hModuleSnap = NULL;
MODULEENTRY32 me32 = {0};

// Take a snapshot of all modules in the specified process.

hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
if (hModuleSnap == INVALID_HANDLE_VALUE)
return (FALSE);

// Fill the size of the structure before using it.

me32.dwSize = sizeof(MODULEENTRY32);

// Walk the module list of the process, and find the module of
// interest. Then copy the information to the buffer pointed
// to by lpMe32 so that it can be returned to the caller.

if (Module32First(hModuleSnap, &me32))
{
do
{
CString csOrgName = me32.szModule;
csOrgName.MakeUpper();

if (csOrgName == lpcModuleName)
{
bFound = TRUE;
}
}
while (!bFound && Module32Next(hModuleSnap, &me32));

bRet = bFound; // if this sets bRet to FALSE, dwModuleID
// no longer exists in specified process
}
else
bRet = FALSE; // could not walk module list

// Do not forget to clean up the snapshot object.

CloseHandle (hModuleSnap);

return (bRet);
}
回复
Mr-Chen 2008-04-10
FindWindow()
SendMessage(..,WM_QUIT,..)

大概是这样的:

hWnd=::FindWindow(NULL,"*******");
if(hWnd)
{
SendMessage(hWnd, WM_QUIT, ...);
}

回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2008-04-10 10:20
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……