Comment puis-je recevoir OutputDebugSsortingng à partir d’un service?

J’essaie d’attraper tous les messages OutputDebugSsortingng (y compris ceux des services) en utilisant le code suivant. Cela a bien fonctionné jusqu’à ma migration vers Windows 7.

Le problème est que, puisque les services Windows Vista s’exécutent dans la session n ° 0 de bas niveau, certaines personnes disent qu’il est impossible de les intercepter et d’autres encore. Qu’est-ce que tu penses?

Est-il possible de modifier le code suivant en augmentant certains droits pour pouvoir recevoir les messages OutputDebugSsortingng à partir de la session n ° 0? En d’autres termes; Est-il possible de partager DBWIN_BUFFER dans la session n ° 0 avec la session n ° 1?

Je dirais que cela devrait être possible, par exemple parce que DebugView peut le faire, et je ne vois aucun assistant de service pouvant envoyer ces messages (par exemple via les canaux nommés) de la session n ° 0 à la session n ° 1, où l’interface graphique est en cours d’exécution.

Le problème sera IMO dans les parameters de sécurité. Quelqu’un peut-il me suggérer comment les modifier?

type TODSThread = class(TThread) protected procedure Execute; override; end; ... procedure TODSThread.Execute; var SharedMem: Pointer; SharedFile: THandle; WaitingResult: DWORD; SharedMessage: ssortingng; DataReadyEvent: THandle; BufferReadyEvent: THandle; SecurityAtsortingbutes: SECURITY_ATTRIBUTES; SecurityDescriptor: SECURITY_DESCRIPTOR; begin SecurityAtsortingbutes.nLength := SizeOf(SECURITY_ATTRIBUTES); SecurityAtsortingbutes.bInheritHandle := True; SecurityAtsortingbutes.lpSecurityDescriptor := @SecurityDescriptor; if not InitializeSecurityDescriptor(@SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION) then Exit; if not SetSecurityDescriptorDacl(@SecurityDescriptor, True, nil, False) then Exit; BufferReadyEvent := CreateEvent(@SecurityAtsortingbutes, False, True, 'DBWIN_BUFFER_READY'); if BufferReadyEvent = 0 then Exit; DataReadyEvent := CreateEvent(@SecurityAtsortingbutes, False, False, 'DBWIN_DATA_READY'); if DataReadyEvent = 0 then Exit; SharedFile := CreateFileMapping(THandle(-1), @SecurityAtsortingbutes, PAGE_READWRITE, 0, 4096, 'DBWIN_BUFFER'); if SharedFile = 0 then Exit; SharedMem := MapViewOfFile(SharedFile, FILE_MAP_READ, 0, 0, 512); if not Assigned(SharedMem) then Exit; while (not Terminated) and (not Application.Terminated) do begin SetEvent(BufferReadyEvent); WaitingResult := WaitForSingleObject(DataReadyEvent, INFINITE); case WaitingResult of WAIT_TIMEOUT: Continue; WAIT_OBJECT_0: begin SharedMessage := Ssortingng(PAnsiChar(SharedMem) + SizeOf(DWORD)); // here I have what I need and process it in the main thread end; WAIT_FAILED: Continue; end; end; UnmapViewOfFile(SharedMem); CloseHandle(SharedFile); end; 

J’ai ajouté la balise C # même si le code est dans Delphi car les atsortingbuts de sécurité sont communs à l’ensemble de l’API Windows et que C # compte de nombreux suiveurs 🙂

Quelqu’un a parlé du même problème dans les forums SysInternals . Leur solution consistait à append “Global \” aux objects nommés .

Alors utilisez ce qui suit

 CreateEvent(@SecurityAtsortingbutes, False, True, 'Global\DBWIN_BUFFER_READY'); CreateEvent(@SecurityAtsortingbutes, False, False, 'Global\DBWIN_DATA_READY'); CreateFileMapping(THandle(-1), @SecurityAtsortingbutes, PAGE_READWRITE, 0, 4096, 'Global\DBWIN_BUFFER');