c# - How can I receive OutputDebugString from service? -
i'm trying catch outputdebugstring messages (including services) using following code. worked fine until migrated windows 7. problem since windows vista services running in low level session #0 people says it's impossible catch them , is. think ? possible modify following code increasing rights able receive outputdebugstring messages session #0 ? in other words; possible share dbwin_buffer in session #0 session #1 ?
i should possible because e.g. debugview can , can't see service helper send messages (e.g. through named pipes) session #0 session #1, gui's running.
the problem imo in security settings. can suggest me how modify them ?
type todsthread = class(tthread) protected procedure execute; override; end; ... procedure todsthread.execute; var sharedmem: pointer; sharedfile: thandle; waitingresult: dword; sharedmessage: string; datareadyevent: thandle; bufferreadyevent: thandle; securityattributes: security_attributes; securitydescriptor: security_descriptor; begin securityattributes.nlength := sizeof(security_attributes); securityattributes.binherithandle := true; securityattributes.lpsecuritydescriptor := @securitydescriptor; if not initializesecuritydescriptor(@securitydescriptor, security_descriptor_revision) exit; if not setsecuritydescriptordacl(@securitydescriptor, true, nil, false) exit; bufferreadyevent := createevent(@securityattributes, false, true, 'dbwin_buffer_ready'); if bufferreadyevent = 0 exit; datareadyevent := createevent(@securityattributes, false, false, 'dbwin_data_ready'); if datareadyevent = 0 exit; sharedfile := createfilemapping(thandle(-1), @securityattributes, page_readwrite, 0, 4096, 'dbwin_buffer'); if sharedfile = 0 exit; sharedmem := mapviewoffile(sharedfile, file_map_read, 0, 0, 512); if not assigned(sharedmem) exit; while (not terminated) , (not application.terminated) begin setevent(bufferreadyevent); waitingresult := waitforsingleobject(datareadyevent, infinite); case waitingresult of wait_timeout: continue; wait_object_0: begin sharedmessage := string(pansichar(sharedmem) + sizeof(dword)); // here have need , process in main thread end; wait_failed: continue; end; end; unmapviewoffile(sharedmem); closehandle(sharedfile); end;
i've added c# tag if code in delphi because security attributes common whole windows api , c# has many followers :)
thanks suggestions
someone talked same issue in sysinternals forums. solution add "global\" named objects.
so use following
createevent(@securityattributes, false, true, 'global\dbwin_buffer_ready'); createevent(@securityattributes, false, false, 'global\dbwin_data_ready'); createfilemapping(thandle(-1), @securityattributes, page_readwrite, 0, 4096, 'global\dbwin_buffer');
Comments
Post a Comment