Cómo escribir software antivirus
El software antivirus generalmente utiliza el mismo método: 1. Deshabilite el proceso del software antivirus; 2. Deshabilite el servicio del software antivirus; 3. Desinstale el software antivirus si está satisfecho. También puede traer la Parte 2 al frente y reiniciar la computadora para que el software antivirus no se inicie. En Windows, se pueden utilizar una serie de API para completar esta función.
Primero, llame a OpenSCManager para obtener el identificador del administrador de servicios.
Luego, llame a OpenService a través del identificador del administrador del servidor para abrir el identificador de servicio del nombre de servicio especificado.
Utilice el identificador de servicio para llamar a ControlService y realizar el control que desee, como pausar, detener, reiniciar y otras operaciones.
Finalmente, recuerde llamar a CloseServiceHandle para cerrar el identificador anterior y liberar recursos del kernel.
El siguiente es un ejemplo que copié de un fragmento de código anterior. Esta función es para preparar la eliminación de un servicio y detenerlo antes de eliminarlo.
BOOL Uninstall()
{
if ( !IsInstalled() )
devuelve VERDADERO;
SC_HANDLE hSCM = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
if ( hSCM == NULL )
{
//MessageBox( NULL, _T( " ¡Error al abrir el administrador de servicios! " ), szServiceName, MB_OK );
return FALSE;
}
SC_HANDLE hService = OpenService( hSCM, szServiceName, SERVICE_STOP | BORRAR );
if ( hService == NULL )
{
CloseServiceHandle( hSCM );
MessageBox( NULL, _T( "¡El servicio no existe!" ), szServiceName, MB_OK );
devuelve FALSE;
}
Estado de SERVICIO_STATUS;
ControlService( hService, SERVICE_CONTROL_STOP, &status );
BOOL bDelete = DeleteService( hService );
CloseServiceHandle( hService );
CloseServiceHandle( hSCM ); p>
if ( bDelete )
{
MessageBox( NULL, _T( "¡Servicio eliminado correctamente!"), szServiceName, MB_OK );
return TRUE ;
}
MessageBox( NULL, _T( "¡Error al eliminar el servicio!"), szServiceName, MB_OK );
//LogEvent(_T ("El servicio no se pudo eliminar"));
devuelve FALSO;
}