????????????????????--C#??C++???
???????????? ???????[ 2012/10/29 10:45:51 ] ????????
??????????????????????????????????????????Щ?????????????????????ò???????Щ???????????????????У?????????????£?????????????????????д???????????£????????MSDN?????д???????????????????????????????????????????
???????????????????C#?????????????C#???????????????????????????????????????????????????????????????Ч???????????????????п??????к????????????????????????????????????????????????????????????β????????????????????????????
????C# Code??
//Return true for successful and false for failed
public bool FindAndKillProcessByName(string name)
{
//Parameter check
if (0 == name.Length)
{
return false;
}
//Find the named process and terminate it
foreach (Process winProc in Process.GetProcesses())
{
//use equals for the task in case we kill
//a wrong process
if (winProc.ProcessName.Equals(name))
{
winProc.Kill();
return true;
}
}
return false;
}
???????C++???????????????????д?????????????????????н?????????????????????????CreateToolhelp32Snapshot()????????#include<tlhelp32.h>?У????????????????????Ч????????????????????????в?????????????????????????????Process32First()?? Process32Next()????????????????????????????????????????????????′?????????OpenProcess()????????????????????SEDebug?????????????????????????PROCESS_TERMINATE ?????????????????????
????C++ Code??
BOOL FindAndKillProcessByName(LPCTSTR strProcessName)
{
if(NULL == strProcessName)
{
return FALSE;
}
HANDLE handle32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS?? 0);
if (INVALID_HANDLE_VALUE == handle32Snapshot)
{
return FALSE;
}
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof( PROCESSENTRY32 );
//Search for all the process and terminate it
if(Process32First(handle32Snapshot?? &pEntry))
{
BOOL bFound = FALSE;
if (!_tcsicmp(pEntry.szExeFile?? strProcessName))
{
bFound = TRUE;
}
while((!bFound)&&Process32Next(handle32Snapshot?? &pEntry))
{
if (!_tcsicmp(pEntry.szExeFile?? strProcessName))
{
bFound = TRUE;
}
}
if(bFound)
{
CloseHandle(handle32Snapshot);
HANDLE handLe = OpenProcess(PROCESS_TERMINATE ?? FALSE?? pEntry.th32ProcessID);
BOOL bResult = TerminateProcess(handLe??0);
return bResult;
}
}
CloseHandle(handle32Snapshot);
return FALSE;
}
???????
??????????C++??C#?????????????????????????????????????????????????????????????в?????????????????????????????????????????????е??2???????????????????????????????????????????????????????????????Щ????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11