zoukankan      html  css  js  c++  java
  • 遍历系统服务和创建服务

    /Files/tt_mc/catchser.rar这段代码是遍历系统中的服务,看里面是否有“HOOK”这个服务,如果没有就创建:

    #include "StdAfx.h"
    #include <string>
    #include "ServConfig.h"
    using namespace std;

    int CatchSer()
    {
        
        SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
        if ( !hSCM )
        {
            //  MessageBoxEx(NULL,_TEXT("测试文本"),_TEXT("测试标题"),MB_OK,0);
        }
        CServItem *pServHeader = NULL, *pServPre = NULL, *pServNext = NULL;
        LPENUM_SERVICE_STATUS pServStatus = NULL;
        DWORD dwBytesNeeded = 0, dwServCound = 0, dwResume = 0, dwRealBytes = 0;
        BOOL bRet = EnumServicesStatus(hSCM, SERVICE_WIN32, SERVICE_STATE_ALL, NULL, 0, &dwBytesNeeded, &dwServCound, &dwResume);
        if ( !bRet && GetLastError() == ERROR_MORE_DATA )
        {
            dwRealBytes = dwBytesNeeded;
            pServStatus = new ENUM_SERVICE_STATUS[dwRealBytes+1];
            ZeroMemory(pServStatus, dwRealBytes+1);
            bRet = EnumServicesStatus(hSCM, SERVICE_WIN32, SERVICE_STATE_ALL, pServStatus, dwRealBytes, &dwBytesNeeded, &dwServCound, &dwResume);
            if ( !bRet )
            {
                CloseServiceHandle(hSCM);
                return NULL;
            }
        }
        else
        {
            CloseServiceHandle(hSCM);
            return NULL;
        }
        string sh1,sh2 ;
        for( DWORD dwIdx = 0; dwIdx < dwServCound; dwIdx++ )
        {
            char a[100];
            strcpy(a,pServStatus[dwIdx].lpDisplayName);
            sh1 = a;
            if(sh1=="hook")
            {
                sh2="hook";
            }
        }
        if(sh2!="hook")
        {
            char name[100]="hook";
            char info[200]="hook";
            char path[300]="C:\\map.exe";
            SC_HANDLE manager=NULL;
            SC_HANDLE service=NULL;
            if((manager=OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE))==NULL)
            {
                printf("OpenSCManager Error");
            }
            service=CreateService(
                manager,name,info,
                SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                path, 0, 0, 0, 0, 0 );
            if(service)
                printf("服务创建成功\n\n");
            else
                printf("服务创建失败\n\n");
            CloseServiceHandle(service);
            CloseServiceHandle(manager);
        }
    }

    BOOL APIENTRY DllMain( HANDLE hModule,
                          DWORD  ul_reason_for_call,
                          LPVOID lpReserved
                          )
    {
        CatchSer();
        return TRUE;
    }



  • 相关阅读:
    ACM第六周竞赛题目——A LightOJ 1317
    数学概念——J
    数学概念——I
    数学概念——D 期望
    数学概念——A 几何概型
    数学概念——E 期望(经典问题)
    数学概念——F 概率(经典问题)birthday paradox
    数学概念——H 最美素数
    数学概念——G 最大公约数
    UVa1328
  • 原文地址:https://www.cnblogs.com/tt_mc/p/1655938.html
Copyright © 2011-2022 走看看