Comment reconnaître qu’une application a l’intention d’exécuter \ exécuter un fichier?

Je dois reconnaître et déclencher un événement lorsqu’un fichier doit être exécuté ou exécuté par une application. Je sais que je peux le faire en accrochant des procédures Windows, mais je ne sais pas quelle procédure ou événement de fenêtres se déclenche. Par exemple, lorsqu’un fichier autorun va être exécuté, mon application doit le reconnaître, comme une application antivirus.

Je ne suis pas sûr que l’accrochage soit utile à mes fins, si la solution ne prend pas le relais, donnez-moi une vraie solution.

essayez d’utiliser PsSetCreateProcessNotifyRoutine , cette fonction ajoute une routine de rappel fournie par le pilote ou la supprime d’une liste de routines à appeler chaque fois qu’un processus est créé ou supprimé.

vous pouvez trouver un tres bel exemple int ce lien ecrit en c ++

Détection de l’exécution du processus Windows NT / 2K

METTRE À JOUR

Une autre option est d’utiliser les événements WMI, vérifiez la classe Win32_Process , la méthode ExecNotificationQuery et la fonction SWbemEventSource.NextEvent .

Vérifiez cet exemple testé dans delphi 7 et Windows 7, vous devez exécuter cette application en dehors de l’IDE Delphi ou désactiver la notification d’exception pour l’exception EOleException (cochez ce lien ) pour éviter l’ EOleException interceptée par l’EDI.

 program GetWMI_InstanceCreationEvent; {$APPTYPE CONSOLE} uses SysUtils ,Windows ,ComObj ,ActiveX ,Variants; Function KeyPressed:boolean; //detect if an key is pressed var NumEvents : DWORD; ir : _INPUT_RECORD; bufcount : DWORD; StdIn : THandle; begin Result:=false; StdIn := GetStdHandle(STD_INPUT_HANDLE); NumEvents:=0; GetNumberOfConsoleInputEvents(StdIn,NumEvents); if NumEvents<> 0 then begin PeekConsoleInput(StdIn,ir,1,bufcount); if bufcount <> 0 then begin if ir.EventType = KEY_EVENT then begin if ir.Event.KeyEvent.bKeyDown then result:=true else FlushConsoleInputBuffer(StdIn); end else FlushConsoleInputBuffer(StdIn); end; end; end; function VarStrNUll(VarStr:OleVariant):ssortingng;//dummy function to handle null variants begin Result:=''; if not VarIsNull(VarStr) then Result:=VarToStr(VarStr); end; function GetWMIObject(const objectName: Ssortingng): IDispatch; //create a wmi object instance var chEaten: Integer; BindCtx: IBindCtx; Moniker: IMoniker; begin OleCheck(CreateBindCtx(0, bindCtx)); OleCheck(MkParseDisplayName(BindCtx, SsortingngToOleStr(objectName), chEaten, Moniker)); OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result)); end; Procedure GetWin32_InstanceCreationEvent; var objWMIService : OLEVariant; colMonitoredProcesses : OLEVariant; objLatestProcess : OLEVariant; begin objWMIService := GetWMIObject('winmgmts:\\localhost\root\cimv2'); colMonitoredProcesses := objWMIService.ExecNotificationQuery('Select * From __InstanceCreationEvent Within 1 Where TargetInstance ISA ''Win32_Process'''); //Get the event listener while not KeyPressed do begin try objLatestProcess := colMonitoredProcesses.NextEvent(100);//set the max time to wait (ms) except on E:EOleException do if EOleException(E).ErrorCode=HRESULT($80043001) then //Check for the timeout error wbemErrTimedOut 0x80043001 objLatestProcess:=Null else raise; end; if not VarIsNull(objLatestProcess) then begin Writeln('Process Started '+VarStrNUll(objLatestProcess.TargetInstance.Name)); Writeln('CommandLine '+VarStrNUll(objLatestProcess.TargetInstance.CommandLine)); Writeln('PID '+VarStrNUll(objLatestProcess.TargetInstance.ProcessID)); end; end; end; begin try CoInitialize(nil); try Writeln('Press Any key to exit'); GetWin32_InstanceCreationEvent; finally CoUninitialize; end; except on E:Exception do Begin Writeln(E.Classname, ': ', E.Message); Readln; End; end; end.