用户登录  |  傲看软件园 用户注册
文章中心广告代码ASP源码PHP源码JSP源码.NET源码源码相关傲看留言板繁體中文
当前位置:傲看软件园文章中心电脑安全安防业界

很巧妙的进程防杀方法

减小字体 增大字体 作者:郁郁小蝎  来源:中国站长学院  发布时间:2008-10-20 20:25:18
刚刚学内核对象,想写个可以防杀的进程,但其他方法太高级,
本菜鸟不感高攀,想了几天,想到一个很本的办法,不正确的
方还请高手指点一下.
程序运行两个事例,每个实例互相监视另外的实例是否存在,
如果不存在,就运行一个.
代码:
// test_process.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "tchar.h"
#include "iostream.h"
#include "windows.h"

LPCTSTR lpszMutex1 = _T("mutex1");
LPCTSTR lpszMutex2 = _T("mutex2");

DWORD WINAPI Thread1(LPARAM lParam);
DWORD WINAPI Thread2(LPARAM lParam);

int main(int argc, char* argv[])
{
    HANDLE hMutex1 = CreateMutex(NULL, FALSE, lpszMutex1);
    if (hMutex1 != NULL)
    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
        CloseHandle(hMutex1);
        cout << lpszMutex1 << " already exist." << endl;
        HANDLE hMutex2 = CreateMutex(NULL, FALSE, lpszMutex2);
        if (hMutex2 != NULL)
        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
            cout << lpszMutex2 << " already exist." << endl;
            return 1;
        }
    }
    DWORD dwThreadId;
    HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Thread1,NULL,0,&dwThreadId);
    CloseHandle(hThread);
    while (1)
    Sleep(1);
    return 0;
}
DWORD WINAPI Thread1(LPARAM lParam)
{
    HANDLE hMutex;
    while (1)
    {
        hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, lpszMutex1);
        if (! hMutex)
        {
            STARTUPINFO si = { sizeof STARTUPINFO };
            PROCESS_INFORMATION pi;
            TCHAR szBuf[MAX_PATH];
            GetModuleFileName(GetModuleHandle(NULL), szBuf, MAX_PATH);
            CreateProcess(szBuf, NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
            CloseHandle(pi.hThread);
            CloseHandle(pi.hProcess);
        }
        CloseHandle(hMutex);
        hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, lpszMutex2);
        if (! hMutex)
        {
            cout << "mutex 2 created." << endl;
            STARTUPINFO si = { sizeof STARTUPINFO };
            PROCESS_INFORMATION pi;
            TCHAR szBuf[MAX_PATH];
            GetModuleFileName(GetModuleHandle(NULL), szBuf, MAX_PATH);
            CreateProcess(szBuf, NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
            CloseHandle(pi.hThread);
            CloseHandle(pi.hProcess);
        }
        CloseHandle(hMutex);
        cout << "Thread      ..." << endl;
        Sleep(1);
    }
    return 1;
}

Tags:

作者:郁郁小蝎

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

精品栏目导航

关于本站 | 网站帮助 | 广告合作 | 下载声明 | 友情连接 | 网站地图
冀ICP备08004437号 | 客服Q:354766721 | 交流群83228313
傲看软件园 - 绿色软件,破解软件下载站! 源码网 源码之家 绿软之家
Copyright © 2003-2010 OkHan.Net. All Rights Reserved .
页面执行时间:1,453.12500 毫秒
Powered by:OkHan CMS Version 4.0.0 SP2