wackyteseo
asked on
Delphi Trace all Windows create and destroyed
Hi ,
I have to do a software that store in a database all activity of pc , when the user open a application and when close the application .
Somethings like winsight but only for event Create and Destroyed
Thank you so much
I have to do a software that store in a database all activity of pc , when the user open a application and when close the application .
Somethings like winsight but only for event Create and Destroyed
Thank you so much
ASKER
ok , thank for this
step one i create a dll
I don't understand how i have information in the main app when is created or closed window ?
step one i create a dll
I don't understand how i have information in the main app when is created or closed window ?
systan ...
this looks awfully much like mathias's dll
> a reference to his site would be in place:
www.madshi.net
this looks awfully much like mathias's dll
> a reference to his site would be in place:
www.madshi.net
Simply you can read all the running processes from the Task Manager - Applications Tab and match and store based on the status.
Check this out:
http://vcldeveloper.com/downloads/ProcessInfo.zip
Check this out:
http://vcldeveloper.com/downloads/ProcessInfo.zip
Geert?
>>this looks awfully much like mathias's dll
yes, depends on the user, alright well try to make another way.
wackyteseo?
Ok;
Are you getting it in the process info?
or what?
>>this looks awfully much like mathias's dll
yes, depends on the user, alright well try to make another way.
wackyteseo?
Ok;
Are you getting it in the process info?
or what?
wackyteseo?
Ok;
Are you getting it in the process info?
or what?
Trace/List what?
Get the application executable name?, like c:\windows\system32\calc.e xe
Get the opened application windows title?, like?
What?
Ok;
Are you getting it in the process info?
or what?
Trace/List what?
Get the application executable name?, like c:\windows\system32\calc.e
Get the opened application windows title?, like?
What?
ASKER
for systan :
if you look Winsight or Winspector , you can see that when open any window , i have a message like
"Window 00d000 , clas blablabla , created "
i have do a little procedure to do this , when open any windows or destroyed i have a called procedure , may be your example do this , but i didn't build a dll.
for jimyX :your solution is good but not is instant , for have a check istant i have set the time short and i have a little freeze of the system, i need the instant message
if you look Winsight or Winspector , you can see that when open any window , i have a message like
"Window 00d000 , clas blablabla , created "
i have do a little procedure to do this , when open any windows or destroyed i have a called procedure , may be your example do this , but i didn't build a dll.
for jimyX :your solution is good but not is instant , for have a check istant i have set the time short and i have a little freeze of the system, i need the instant message
So do you want to get the application executable name?, like c:\windows\system32\calc.e xe
or get the opened application windows caption title?
example output like; ?
CREATED c:\windows\system32\calc.e xe
...
DESTROYED c:\windows\system32\calc.e xe
or get the opened application windows caption title?
example output like; ?
CREATED c:\windows\system32\calc.e
...
DESTROYED c:\windows\system32\calc.e
> "i need the instant message"
You need to explain a bit more here, because the demo works fine here.
Anyway, I created a sample project that reads all the running (or open) applications and show their details in a Listview and once any application is terminated then the details will be moved to another Listview (or they can be stored in a database instead).
Because EE restricts uploading certain extensions, you need to add the following file to the attached sample directory before you compile it:
ProcessInfo.inc
The file "ProcessInfo.inc" can be found in the source link:
http://vcldeveloper.com/downloads/ProcessInfo.zip
Sample-Project.zip
You need to explain a bit more here, because the demo works fine here.
Anyway, I created a sample project that reads all the running (or open) applications and show their details in a Listview and once any application is terminated then the details will be moved to another Listview (or they can be stored in a database instead).
Because EE restricts uploading certain extensions, you need to add the following file to the attached sample directory before you compile it:
ProcessInfo.inc
The file "ProcessInfo.inc" can be found in the source link:
http://vcldeveloper.com/downloads/ProcessInfo.zip
Sample-Project.zip
Updated sample project.
Do not forget to add "ProcessInfo.inc".
Just to let you know, this is just a sample and it can be changed, updated and improved to match your requirements.
Sample-Project-2.zip
Do not forget to add "ProcessInfo.inc".
Just to let you know, this is just a sample and it can be changed, updated and improved to match your requirements.
Sample-Project-2.zip
ASKER
for systan :
yes i want output like as you write , and if it is possible also the handle of process , but for the last not is a problem
yes i want output like as you write , and if it is possible also the handle of process , but for the last not is a problem
Here's the mathook code updated;
You just need to send information back to the form.
Good Luck
library mathook;
uses
Windows, SysUtils,
Messages;
type
THookRec = record
hMatHook: HHOOK;
hMatWnd: HWND;
oldProc: Integer;
end;
var
map: DWord;
buf: ^THookRec;
// hook proc - waits for target window to be created
function MatHookProc(nCode: Integer; wp: wParam; lp: lParam): LongInt; stdcall;
begin
try
if (nCode > 0) then
begin
Case nCode of
HSHELL_WINDOWCREATED:
begin
//sends message to the form that high level window is created
//sends the getwindowtext
//sends the getcommandline
//sends the gethandle
end;
HSHELL_WINDOWDESTROYED:
begin
//sends message to the form that high level window has been destroyed
end;
end;
end;
Result := CallNextHookEx(buf^.hMatHook, nCode, wp, lp);
except
Result := 0;
end;
end;
// sets up hook
function SetHook: Boolean; stdcall; export;
begin
try
Result := false;
if (not assigned(buf)) then
begin
map := CreateFileMapping(DWord(-1), nil, PAGE_READWRITE, 0, SizeOf(THookRec), 'HookRecMemBlock');
buf := MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, 0);
buf^.hMatHook := SetWindowsHookEx(WH_SHELL, @MatHookProc, hInstance, 0);
Result := true;
end;
except
Result := false;
end;
end;
// removes hook
function RemoveHook: Boolean; stdcall; export;
begin
Result := false;
if (assigned(buf)) then
begin
// tell our new wnd proc to stop subclassing
// (has to be done in context of target process)
SendMessage(buf^.hMatWnd, wm_User + 1, 1, 0);
if (buf^.hMatHook <> 0) then UnhookWindowsHookEx(buf^.hMatHook);
buf^.hMatHook := 0;
UnmapViewOfFile(buf);
buf := nil;
Result := true;
end;
end;
// DLL entry point
procedure DllEntry(dwReason: DWord);
begin
Case dwReason of
DLL_PROCESS_ATTACH:
begin
if (not assigned(buf)) then
begin
map := OpenFileMapping(FILE_MAP_ALL_ACCESS, false, 'HookRecMemBlock');
buf := MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, 0);
CloseHandle(map);
map := 0;
end;
end;
DLL_PROCESS_DETACH:
begin
UnmapViewOfFile(buf);
buf := nil;
end;
end;
end;
exports
SetHook,
RemoveHook;
// main
begin
DisableThreadLibraryCalls(hInstance);
DllProc := @DLLEntry;
DllEntry(DLL_PROCESS_ATTACH);
end.
That's the nearest possible automate solution that you want;You just need to send information back to the form.
Good Luck
I just want to share that this are the links I refer to change mathook code;
http://www.delphimaster.net/view/4-17442/all
http://groups.google.com/group/borland.public.delphi.nativeapi.win32/browse_thread/thread/f848ef57a76d2939
http://stackoverflow.com/questions/299370/what-do-i-have-to-do-to-make-my-wh-shell-or-wh-cbt-hook-procedure-receive-events
if you have the time to analyze what's in the links, then I am sure you will get what you want.
http://www.delphimaster.net/view/4-17442/all
http://groups.google.com/group/borland.public.delphi.nativeapi.win32/browse_thread/thread/f848ef57a76d2939
http://stackoverflow.com/questions/299370/what-do-i-have-to-do-to-make-my-wh-shell-or-wh-cbt-hook-procedure-receive-events
if you have the time to analyze what's in the links, then I am sure you will get what you want.
ASKER
Ho systan , i have tried but i don't know where i wrong , the hook don't work
i attach file of example
i attach file of example
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wowwww , good solution for me , if i want also the number of handle ?
p.s. Thank you also for jimyx
p.s. Thank you also for jimyx
ASKER
if is possible have also the handle of window
SendMessage(FindWindowEx(F indWindow( 'TForm1', nil), 0, 'TListBox', nil), LB_INSERTSTRING, 0, Integer(PChar(getcommandli ne + ' CREATED with HANDLE ' + IntToStr(wp) )));
ASKER
thank you so much
Open in new window
by_Markus_alias_DaFox_in_E