Chinaunix首页 | 论坛 | 博客
  • 博客访问: 582295
  • 博文数量: 137
  • 博客积分: 4040
  • 博客等级: 上校
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-08 13:05
文章分类

全部博文(137)

文章存档

2011年(10)

2010年(23)

2009年(104)

分类: WINDOWS

2009-09-18 15:45:17

1、加入#include "psapi.h",,,Psapi.lib(连接时要用)
 

DWORD FindProcess(char *strProcessName)
{
    DWORD aProcesses[1024], cbNeeded, cbMNeeded;
    HMODULE hMods;
    HANDLE hProcess;
    char szProcessName[MAX_PATH];

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 0;
    for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++)
    {
        //_tprintf(_T("%d\t"), aProcesses[i]);

        hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i]);
        EnumProcessModules(hProcess, &hMods, sizeof(hMods), &cbMNeeded);
        GetModuleFileNameEx( hProcess, hMods, szProcessName,sizeof(szProcessName));
        //GetModuleBaseName(hProcess,hMods,chBuf,nBufSize))


        if(strstr(szProcessName, strProcessName))
        {
            //_tprintf(_T("%s;"), szProcessName);

            TRACE("找到执行的文件名");

            return(aProcesses[i]);
        }
        //_tprintf(_T("\n"));

    }
    return 0;
}


BOOL GetDebugPriv()
{
    HANDLE hToken;
    LUID sedebugnameValue;
    TOKEN_PRIVILEGES tkp;

    if ( ! OpenProcessToken( GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
    {
        return FALSE;
    }
    

    if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) )
    {
        CloseHandle( hToken );
        return FALSE;
    }

    tkp.PrivilegeCount = 1;
    tkp.Privileges[0].Luid = sedebugnameValue;
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    if (!AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
    {
        CloseHandle( hToken );
        return FALSE;
    }

    return TRUE;
}

 

void main()
{
    HANDLE hYourTargetProcess = OpenProcess(PROCESS_QUERY_INFORMATION | // Required by Alpha

         PROCESS_CREATE_THREAD | // For CreateRemoteThread

         PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx

         PROCESS_VM_WRITE, // For WriteProcessMemory

         FALSE, FindProcess("C:\\vs2005project\\VNCCCCMDConsumer\\release\\VNCCCCMDConsumer.exe"));

    if(hYourTargetProcess == NULL)
    {
        TRACE("000000000000000000");
    }
    else{
    TRACE("11111111111111111111");
    }
    GetDebugPriv();
    TerminateProcess(hYourTargetProcess, 0);
}

 

2、WinExec("TaskKill /F /IM VNCCCCMDConsumer.exe",SW_SHOWMINIMIZED);

阅读(2208) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~