我用枚举函数得到子窗口的类总得不到,大家看看我的代码,指点一下。 (200分)

  • 主题发起人 主题发起人 路远
  • 开始时间 开始时间

路远

Unregistered / Unconfirmed
GUEST, unregistred user!
type<br>&nbsp; EnumChildProc = function (Hwnd: THandle;<br>&nbsp; Param: Pointer): Boolean; stdcall;<br>var<br>foundwnd,hwnd,childhwnd :thandle;<br><br>function GetTitle (Hwnd : THandle; Param: Pointer): Boolean; stdcall;<br>var<br>foundchildhwnd,HINSTANCE,mydlg &nbsp;:THandle;<br>childClassName,childwindowtext,partStr,abc,DlgltemText,path : string;<br>ClassName:Array [Byte] of Char;<br>begin<br>&nbsp; GetClassName (hwnd, ClassName, sizeof(ClassName));<br>&nbsp; &nbsp; &nbsp;if &nbsp;StrComp(ClassName, '#32770')=0 then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; FormCallBack.ListBox1.Items.Add(IntToStr (Hwnd) + ': '+ClassName);<br>&nbsp; &nbsp; &nbsp; foundwnd:= Hwnd ;<br>&nbsp; &nbsp; &nbsp; Setlength(childClassName,100);<br>&nbsp; &nbsp; &nbsp; childhwnd:=getwindow(foundwnd,GW_CHILD) ;//得到foundwnd句炳的子窗口句炳<br>&nbsp; &nbsp; &nbsp; GetClassName (childhwnd, PChar (childClassName), Length (childClassName)); // 得到子窗口的类<br>&nbsp; &nbsp; &nbsp; if StrComp(PChar(childClassName), 'Static')=0 &nbsp; then &nbsp; &nbsp;//<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FormCallBack.ListBox1.Items.Add(IntToStr(childhwnd)+':'+childClassName);//<br>&nbsp; &nbsp; &nbsp; &nbsp;foundchildhwnd:=childhwnd ;<br>&nbsp; &nbsp; &nbsp; &nbsp;Setlength(childwindowtext,100);<br>&nbsp; &nbsp; &nbsp; &nbsp;getwindowtext(foundchildhwnd,pchar(childwindowtext),100);<br>&nbsp; &nbsp; &nbsp; &nbsp; childwindowtext:=pchar(childwindowtext);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if AnsiStartsText('d:/',childwindowtext)=true &nbsp; &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FormCallBack.ListBox1.Items.Add(IntToStr(foundchildhwnd)+':'+childwindowtext);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;end;<br>end; &nbsp; &nbsp; &nbsp;<br>procedure TFormCallback.Timer1Timer(Sender: TObject);<br>&nbsp;var<br>&nbsp; EWProc: EnumChildProc;<br>begin<br>&nbsp; ListBox1.Items.Clear;<br>&nbsp; EWProc := GetTitle;<br>&nbsp; EnumChildWindows (childhwnd,@EWProc, 0);<br>end;<br>&nbsp; &nbsp;
 
unit enumStuff;<br><br>// &nbsp;Delphi 4,5 enumeration implementation of several win32 APIs<br>// &nbsp;Dragon PC <br><br>interface<br><br>uses windows;<br><br>type TACardinal &nbsp; = array [0..maxInt shr 2-1] of cardinal;<br>&nbsp; &nbsp; &nbsp;TPACardinal &nbsp;= ^TACardinal;<br>&nbsp; &nbsp; &nbsp;TDACardinal &nbsp;= array of cardinal;<br><br>type TOperatingSystem = (osUnknown, osWin311, osWin95, osWin95osr2, osWin98, osWinNT3, osWinNT4, osWinNT4SP4, osWinNT5);<br>function GetOperatingSystem : TOperatingSystem;<br>// Tests which system is running...<br><br>type TExeType = (etUnknown, etDos, etWin16, etConsole, etWin32);<br>function GetExeType(exefile: string) : TExeType;<br>// Determines the type of the executable.<br><br>type TWindowList &nbsp; &nbsp; &nbsp; &nbsp; = array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pid &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tid &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; owner &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; visible &nbsp; : boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enabled &nbsp; : boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inTaskbar : boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rect &nbsp; &nbsp; &nbsp;: TRect;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title &nbsp; &nbsp; : string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className : string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TThreadList &nbsp; &nbsp; &nbsp; &nbsp; = array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pid &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tid &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; windows &nbsp; : TWindowList;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TProcessList &nbsp; &nbsp; &nbsp; &nbsp;= array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pid &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name &nbsp; &nbsp; &nbsp;: string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exeType &nbsp; : TExeType;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; threads &nbsp; : TThreadList;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TDesktopList &nbsp; &nbsp; &nbsp; &nbsp;= array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name &nbsp; &nbsp; &nbsp;: string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; windows &nbsp; : TWindowList;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TWindowStationList &nbsp;= array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name &nbsp; &nbsp; &nbsp;: string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; desktops &nbsp;: TDesktopList;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TCachedPasswordList = array of record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resource &nbsp;: string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password &nbsp;: string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resType &nbsp; : byte;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>function GetProcessList (threadsToo: boolean = false; windowsToo: boolean = false) : TProcessList;<br>// Lists the currently running processes.<br><br>function GetThreadList (pid: cardinal = 0; windowsToo: boolean = false) : TThreadList;<br>// Lists the currently running threads of the process "pid" or of all processes.<br><br>function GetWindowList (pid: cardinal = 0; tid: cardinal = 0; onlyThoseInTaskbar: boolean = false) : TWindowList;<br>// Lists the currently existing top level windows of the process "pid" or of all<br>// processes and of the thread "tid" or of all threads.<br><br>function GetChildWindowList (window: cardinal) : TWindowList;<br>// Lists the the child windows of "window".<br><br>function GetWindowStationList (desktopsToo: boolean = false; windowsToo: boolean = false) : TWindowStationList;<br>// Lists the currently existing window stations. &nbsp;(works only under winNT)<br><br>function GetDesktopList (ws: cardinal = 0; windowsToo: boolean = false) : TDesktopList;<br>// Lists the currently existing desktops. &nbsp;(works only under winNT)<br><br>function GetDesktopWindowList (dt: cardinal = 0) : TWindowList;<br>// Lists the currently existing windows of the current desktop. &nbsp;(works only under winNT)<br><br>function GetCachedPasswords : TCachedPasswordList;<br>// Lists all cached passwords of the currently logged in user. &nbsp;(works only under win95/98)<br><br>implementation<br><br>uses ShellAPI, sysUtils;<br><br>type TPThreadList &nbsp; &nbsp; &nbsp; &nbsp;= ^TThreadList;<br>&nbsp; &nbsp; &nbsp;TPProcessList &nbsp; &nbsp; &nbsp; = ^TProcessList;<br><br>var OS &nbsp; &nbsp; &nbsp;: TOperatingSystem;<br>&nbsp; &nbsp; OSReady : boolean = false;<br>function GetOperatingSystem : TOperatingSystem;<br>var os1 : TOSVersionInfo;<br>begin<br>&nbsp; if not OSReady then begin<br>&nbsp; &nbsp; OSReady:=true;<br>&nbsp; &nbsp; os1.dwOSVersionInfoSize:=sizeOf(os1); GetVersionEx(os1);<br>&nbsp; &nbsp; case os1.dwPlatformID of<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32s &nbsp; &nbsp; &nbsp; &nbsp;: OS:=osWin311;<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_WINDOWS : if (os1.dwMajorVersion=4) and (os1.dwMinorVersion=0) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if os1.dwBuildNumber&gt;1000 then OS:=osWin95osr2 else OS:=osWin95;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end else if (os1.dwMajorVersion=4) and (os1.dwMinorVersion=10) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OS:=osWin98<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else OS:=osUnknown;<br>&nbsp; &nbsp; &nbsp; VER_PLATFORM_WIN32_NT &nbsp; &nbsp; &nbsp;: case os1.dwMajorVersion of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0..3 : OS:=osWinNT3;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp;: if string(os1.szCSDVersion)='Service Pack 4' then OS:=osWinNT4SP4<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OS:=osWinNT4;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;5 &nbsp; &nbsp;: OS:=osWinNT5;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OS:=osUnknown;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; result:=OS;<br>end;<br><br>const MAX_MODULE_NAME32 = 255;<br>type<br>&nbsp; TProcessEntry32 = record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cntUsage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ProcessID &nbsp; &nbsp; &nbsp; : DWORD; &nbsp;// this process<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32DefaultHeapID &nbsp; : DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ModuleID &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp;// associated exe<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cntThreads &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ParentProcessID : DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// this process's parent process<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pcPriClassBase &nbsp; &nbsp; &nbsp;: integer; &nbsp; &nbsp; &nbsp;// Base priority of process's threads<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szExeFile &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array [0..MAX_PATH-1] of char; &nbsp; &nbsp;// Path<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; TThreadEntry32 &nbsp;= record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cntUsage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ThreadID &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp;// this thread<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32OwnerProcessID &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// Process this thread is associated with<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tpBasePri &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tpDeltaPri &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; TModuleEntry32 &nbsp;= record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWORD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ModuleID &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// This module<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; th32ProcessID &nbsp; &nbsp; &nbsp; : DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// owning process<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GlblcntUsage &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// Global usage count on the module<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProccntUsage &nbsp; &nbsp; &nbsp; &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// Module usage count in th32ProcessID's context<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modBaseAddr &nbsp; &nbsp; &nbsp; &nbsp; : pointer; &nbsp; &nbsp; &nbsp;// Base address of module in th32ProcessID's context<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modBaseSize &nbsp; &nbsp; &nbsp; &nbsp; : DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// Size in bytes of module starting at modBaseAddr<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hModule &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : HMODULE; &nbsp; &nbsp; &nbsp;// The hModule of this module in th32ProcessID's context<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szModule &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: array [0..MAX_MODULE_NAME32] of char;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szExePath &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : array [0..MAX_PATH-1] of char;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>const TH32CS_SnapProcess = 2;<br>&nbsp; &nbsp; &nbsp; TH32CS_SnapThread &nbsp;= 4;<br>&nbsp; &nbsp; &nbsp; TH32CS_SnapModule &nbsp;= 8;<br>var &nbsp; //PsApiHandle &nbsp; &nbsp;: cardinal = 0;<br>&nbsp; &nbsp; &nbsp; CreateToolhelp32Snapshot :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (dwFlags,th32ProcessID: cardinal) : cardinal; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Process32First :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lppe: TProcessEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Process32Next :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lppe: TProcessEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Thread32First :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lpte: TThreadEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Thread32Next :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lpte: TThreadEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Module32First :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lpme: TModuleEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; Module32Next :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hSnapshot: cardinal; var lpme: TModuleEntry32) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; EnumProcesses :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (idProcess: TPACardinal; cb: cardinal; var cbNeeded: cardinal) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; EnumProcessModules :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hProcess: cardinal; var hModule: cardinal; cb: cardinal; var cbNeeded: cardinal) : bool; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; &nbsp; GetModuleFileNameEx :<br>&nbsp; &nbsp; &nbsp; &nbsp; function (hProcess,hModule: cardinal; fileName: PChar; nSize: cardinal) : cardinal; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; = nil;<br><br>function TestToolhelpFunctions : boolean;<br>var c1 : cardinal;<br>begin<br>&nbsp; c1:=GetModuleHandle('kernel32');<br>&nbsp; @CreateToolhelp32Snapshot:=GetProcAddress(c1,'CreateToolhelp32Snapshot');<br>&nbsp; @Process32First &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:=GetProcAddress(c1,'Process32First' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br>&nbsp; @Process32Next &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :=GetProcAddress(c1,'Process32Next' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; @Thread32First &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :=GetProcAddress(c1,'Thread32First' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; @Thread32Next &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:=GetProcAddress(c1,'Thread32Next' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br>&nbsp; @Module32First &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :=GetProcAddress(c1,'Module32First' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; @Module32Next &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:=GetProcAddress(c1,'Module32Next' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br>&nbsp; result:=(@CreateToolhelp32Snapshot&lt;&gt;nil) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (@Process32First&lt;&gt;nil) and (@Process32Next&lt;&gt;nil) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (@Thread32First&lt;&gt;nil) and (@Thread32Next&lt;&gt;nil) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (@Module32First&lt;&gt;nil) and (@Module32Next&lt;&gt;nil);<br>end;<br><br>{function TestPsApi : boolean;<br>begin<br>&nbsp; if PsApiHandle=0 then begin<br>&nbsp; &nbsp; PsApiHandle:=LoadLibrary('psapi');<br>&nbsp; &nbsp; result:=PsApiHandle&lt;&gt;0;<br>&nbsp; &nbsp; if result then begin<br>&nbsp; &nbsp; &nbsp; @EnumProcesses &nbsp; &nbsp; &nbsp;:=GetProcAddress(PsApiHandle,'EnumProcesses' &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; @EnumProcessModules :=GetProcAddress(PsApiHandle,'EnumProcessModules' &nbsp;);<br>&nbsp; &nbsp; &nbsp; @GetModuleFileNameEx:=GetProcAddress(PsApiHandle,'GetModuleFileNameExA');<br>&nbsp; &nbsp; &nbsp; result:=(@EnumProcesses&lt;&gt;nil) and (@EnumProcessModules&lt;&gt;nil) and (@GetModuleFileNameEx&lt;&gt;nil);<br>&nbsp; &nbsp; end;<br>&nbsp; end else result:=true;<br>end;}<br><br>function GetExeType(exefile: string) : TExeType;<br>var c1 &nbsp;: cardinal;<br>&nbsp; &nbsp; sfi : TSHFileInfo;<br>&nbsp; &nbsp; s1 &nbsp;: string;<br>begin<br>&nbsp; c1:=SHGetFileInfo(pchar(exefile),0,sfi,SizeOf(sfi),SHGFI_EXETYPE);<br>&nbsp; s1:=chr(c1 and $ff)+chr((c1 and $ff00) shr 8);<br>&nbsp; if &nbsp; &nbsp; &nbsp; s1='MZ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then result:=etDos<br>&nbsp; else if &nbsp;s1='NE' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then result:=etWin16<br>&nbsp; else if (s1='PE') and (hiWord(c1)=0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then result:=etConsole<br>&nbsp; else if (s1='PE') and (hiWord(c1)&gt;0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then result:=etWin32<br>&nbsp; else if CompareText(AnsiUpperCase(ExtractFileName(exefile)),AnsiUpperCase('winoa386.mod'))=0 then result:=etDos<br>&nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result:=etUnknown;<br>end;<br><br>function NT4_EnumProcessesAndThreads(pl: TPProcessList; tl: TPThreadList; windowsToo: boolean) : boolean;<br>type TPerfDataBlock &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = packed record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; signature &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: array [0..3] of wchar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; littleEndian &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; revision &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalByteLength &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headerLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numObjectTypes &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultObject &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; systemTime &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TSystemTime;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfTime &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : comp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfFreq &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : comp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfTime100nSec &nbsp; &nbsp; &nbsp; &nbsp;: comp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; systemNameLength &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; systemnameOffset &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TPPerfDataBlock &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ^TPerfDataBlock;<br><br>&nbsp; &nbsp; &nbsp;TPerfObjectType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= packed record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalByteLength &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; definitionLength &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headerLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectNameTitleIndex &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectNameTitle &nbsp; &nbsp; &nbsp; &nbsp;: PWideChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectHelpTitleIndex &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectHelpTitle &nbsp; &nbsp; &nbsp; &nbsp;: PWideChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detailLevel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numCounters &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultCounter &nbsp; &nbsp; &nbsp; &nbsp; : integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numInstances &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; codePage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfTime &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : comp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfFreq &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : comp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TPPerfObjectType &nbsp; &nbsp; &nbsp; &nbsp; = ^TPerfObjectType;<br><br>&nbsp; &nbsp; &nbsp;TPerfCounterDefinition &nbsp; = packed record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byteLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterNameTitleIndex &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterNameTitle &nbsp; &nbsp; &nbsp; : PWideChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterHelpTitleIndex &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterHelpTitle &nbsp; &nbsp; &nbsp; : PWideChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultScale &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; defaultLevel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterOffset &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TPPerfCounterDefinition &nbsp;= ^TPerfCounterDefinition;<br><br>&nbsp; &nbsp; &nbsp;TPerfInstanceDefinition &nbsp;= packed record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byteLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentObjectTitleIndex : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentObjectInstance &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uniqueID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameOffset &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TPPerfInstanceDefinition = ^TPerfInstanceDefinition;<br>&nbsp; &nbsp; &nbsp;TAPChar &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= array [0..maxInt div 4-1] of pchar;<br>&nbsp; &nbsp; &nbsp;TPCardinal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ^cardinal;<br>var &nbsp;i1,i2,i3,i4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: integer;<br>&nbsp; &nbsp; &nbsp;b1,b2,b3,b4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: boolean;<br>&nbsp; &nbsp; &nbsp;bt,bp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: boolean;<br>&nbsp; &nbsp; &nbsp;c1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal;<br>&nbsp; &nbsp; &nbsp;pCard &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TPCardinal;<br>&nbsp; &nbsp; &nbsp;perfDataBlock &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TPPerfDataBlock;<br>&nbsp; &nbsp; &nbsp;perfObjectType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TPPerfObjectType;<br>&nbsp; &nbsp; &nbsp;perfCounterDef &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TPPerfCounterDefinition;<br>&nbsp; &nbsp; &nbsp;perfInstanceDef &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TPPerfInstanceDefinition;<br>begin<br>&nbsp; result:=false;<br>&nbsp; bt:=tl=nil; if not bt then tl^:=nil; bp:=pl=nil; if not bp then pl^:=nil;<br>&nbsp; if bt and bp then exit;<br>&nbsp; perfDataBlock:=nil;<br>&nbsp; try<br>&nbsp; &nbsp; i1:=$10000;<br>&nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; ReallocMem(perfDataBlock,i1); i2:=i1;<br>&nbsp; &nbsp; &nbsp; i4:=RegQueryValueEx(HKEY_PERFORMANCE_DATA,'230 232',nil,@i3,pointer(perfDataBlock),@i2);<br>&nbsp; &nbsp; &nbsp; if i4=ERROR_MORE_DATA then i1:=i1*2;<br>&nbsp; &nbsp; until (i4&lt;&gt;ERROR_MORE_DATA);<br>&nbsp; &nbsp; if i4&lt;&gt;ERROR_SUCCESS then exit;<br>&nbsp; &nbsp; perfObjectType:=pointer(cardinal(perfDataBlock)+perfDataBlock^.headerLength);<br>&nbsp; &nbsp; for i1:=0 to integer(perfDataBlock^.numObjectTypes)-1 do begin<br>&nbsp; &nbsp; &nbsp; b1:= &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (pl&lt;&gt;nil) and (perfObjectType^.objectNameTitleIndex=230); &nbsp; // 230 -&gt; "Process"<br>&nbsp; &nbsp; &nbsp; b2:=(not b1) and (tl&lt;&gt;nil) and (perfObjectType^.objectNameTitleIndex=232); &nbsp; // 232 -&gt; "Thread"<br>&nbsp; &nbsp; &nbsp; if b1 or b2 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; perfCounterDef:=pointer(cardinal(perfObjectType)+perfObjectType^.headerLength);<br>&nbsp; &nbsp; &nbsp; &nbsp; for i2:=0 to perfObjectType^.numCounters-1 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b3:= &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;perfCounterDef^.counterNameTitleIndex=784; &nbsp; &nbsp;// 784 -&gt; "ID Process"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b4:=(not b3) and (perfCounterDef^.counterNameTitleIndex=804); &nbsp; // 804 -&gt; "ID Thread"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if b3 or b4 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfInstanceDef:=pointer(cardinal(perfObjectType)+perfObjectType^.definitionLength);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if b1 then SetLength(pl^,perfObjectType^.numInstances-1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; SetLength(tl^,perfObjectType^.numInstances-1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i3:=0 to perfObjectType^.numInstances-2 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c1:=TPCardinal(cardinal(perfInstanceDef)+perfInstanceDef^.byteLength+perfCounterDef^.counterOffset)^;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if b1 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pl^[i3].pid:=c1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if c1&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pl^[i3].name:=wideString(PWideChar(cardinal(perfInstanceDef)+perfInstanceDef.nameOffset));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pl^[i3].name&lt;&gt;'System' then pl^[i3].name:=pl^[i3].name+'.exe';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end else pl^[i3].name:='[System Process]';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end else if b3 then tl^[i3].pid:=c1 else tl^[i3].tid:=c1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pCard:=pointer(cardinal(perfInstanceDef)+perfInstanceDef^.byteLength);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perfInstanceDef:=pointer(cardinal(pCard)+pCard^);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(perfCounterDef);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; bt:=bt or b2; bp:=bp or b1; if bt and bp then break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; perfObjectType:=pointer(cardinal(perfObjectType)+perfObjectType^.totalByteLength);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; result:=((pl&lt;&gt;nil) and (pl^&lt;&gt;nil)) or ((tl&lt;&gt;nil) and (tl^&lt;&gt;nil));<br>&nbsp; &nbsp; if (tl&lt;&gt;nil) and windowsToo then<br>&nbsp; &nbsp; &nbsp; if windowsToo then<br>&nbsp; &nbsp; &nbsp; &nbsp; for i1:=0 to high(tl^) do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (tl^[i1].pid&lt;&gt;0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tl^[i1].windows:=GetWindowList(tl^[i1].pid,tl^[i1].tid);<br>&nbsp; finally FreeMem(perfDataBlock) end;<br>end;<br><br>function GetProcessList(threadsToo: boolean = false; windowsToo: boolean = false) : TProcessList;<br>var c1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; i1,i2,i3,i4 : integer;<br>&nbsp; &nbsp; tl &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TThreadList;<br>&nbsp; &nbsp; pe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TProcessEntry32;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; if GetOperatingSystem in [osWin95,osWin95osr2,osWin98,osWinNT5] then begin<br>&nbsp; &nbsp; if not TestToolhelpFunctions then begin<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'Toolhelp functions not available.','Error...',0);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; c1:=CreateToolHelp32Snapshot(TH32CS_SnapProcess,0);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; i1:=0;<br>&nbsp; &nbsp; &nbsp; pe.dwSize:=sizeOf(pe);<br>&nbsp; &nbsp; &nbsp; if Process32First(c1,pe) then<br>&nbsp; &nbsp; &nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(result,i1+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].pid:=pe.th32ProcessID; result[i1].name:=pe.szExeFile;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].exeType:=GetExeType(result[i1].name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(i1);<br>&nbsp; &nbsp; &nbsp; &nbsp; until not Process32Next(c1,pe);<br>&nbsp; &nbsp; finally CloseHandle(c1) end;<br>&nbsp; &nbsp; if threadsToo then tl:=GetThreadList(0,windowsToo);<br>&nbsp; end else if GetOperatingSystem in [osWinNT3,osWinNT4,osWinNT4SP4] then<br>&nbsp; &nbsp; if ( &nbsp; &nbsp; threadsToo &nbsp;and (not NT4_EnumProcessesAndThreads(@result,@tl,windowsToo))) or &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;((not threadsToo) and (not NT4_EnumProcessesAndThreads(@result,nil,false &nbsp; &nbsp; ))) then<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'Error reading Performace Data.','Error...',0);<br>{ &nbsp; &nbsp;if not TestPsApi then begin<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'"PsApi.dll" not found.','Error...',0);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SetLength(s1,MAX_PATH+1);<br>&nbsp; &nbsp; SetLength(s1,GetModuleFileName(psApiHandle,pchar(s1),MAX_PATH));<br>&nbsp; &nbsp; c1:=100; SetLength(ac,c1);<br>&nbsp; &nbsp; if EnumProcesses(pointer(ac),4*c1,c2) then begin<br>&nbsp; &nbsp; &nbsp; while 4*c1=c2 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; inc(c1,100); SetLength(ac,c1); EnumProcesses(pointer(ac),4*c1,c2);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; SetLength(result,c2 div 4);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; for i1:=0 to high(result) do begin<br>&nbsp; &nbsp; &nbsp; result[i1].pid:=ac[i1];<br>&nbsp; &nbsp; &nbsp; c1:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,false,ac[i1]);<br>&nbsp; &nbsp; &nbsp; if c1&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if EnumProcessModules(c1,c2,4,c3) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(result[i1].name,MAX_PATH+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetModuleFileNameEx(c1,c2,PChar(result[i1].name),length(result[i1].name))&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].name:=string(PChar(result[i1].name));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].exeType:=GetExeType(result[i1].name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end else begin result[i1].name:=''; result[i1].exeType:=etUnknown end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; finally CloseHandle(c1) end;<br>&nbsp; &nbsp; end;<br>&nbsp; end; }<br>&nbsp; i4:=high(tl);<br>&nbsp; if i4&gt;0 then<br>&nbsp; &nbsp; for i1:=0 to i4 do<br>&nbsp; &nbsp; &nbsp; for i2:=high(result) downto 0 do<br>&nbsp; &nbsp; &nbsp; &nbsp; if tl[i1].pid=result[i2].pid then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i3:=length(result[i2].threads); setLength(result[i2].threads,i3+1); result[i2].threads[i3]:=tl[i1];<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>end;<br><br>function GetThreadList(pid: cardinal = 0; windowsToo: boolean = false) : TThreadList;<br>var c1 : cardinal;<br>&nbsp; &nbsp; i1 : integer;<br>&nbsp; &nbsp; te : TThreadEntry32;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; if GetOperatingSystem in [osWin95,osWin95osr2,osWin98,osWinNT5] then begin<br>&nbsp; &nbsp; if not TestToolhelpFunctions then begin<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'Toolhelp functions not available.','Error...',0);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; c1:=CreateToolHelp32Snapshot(TH32CS_SnapThread,0);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; i1:=0;<br>&nbsp; &nbsp; &nbsp; te.dwSize:=sizeOf(te);<br>&nbsp; &nbsp; &nbsp; if Thread32First(c1,te) then<br>&nbsp; &nbsp; &nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pid=0) or (pid=te.th32OwnerProcessID) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(result,i1+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].tid:=te.th32ThreadID; result[i1].pid:=te.th32OwnerProcessID;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(i1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; until not Thread32Next(c1,te);<br>&nbsp; &nbsp; finally CloseHandle(c1) end;<br>&nbsp; &nbsp; if windowsToo then<br>&nbsp; &nbsp; &nbsp; for i1:=0 to high(result) do<br>&nbsp; &nbsp; &nbsp; &nbsp; if (result[i1].pid&lt;&gt;0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].windows:=GetWindowList(result[i1].pid,result[i1].tid);<br>&nbsp; end else if GetOperatingSystem in [osWinNT3,osWinNT4,osWinNT4SP4] then<br>&nbsp; &nbsp; if not NT4_EnumProcessesAndThreads(nil,@result,windowsToo) then<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'Error reading Performace Data.','Error...',0);<br>end;<br><br>var ew_pid, ew_tid &nbsp; &nbsp; &nbsp; &nbsp;: cardinal;<br>&nbsp; &nbsp; ew_onlyThoseInTaskbar : boolean;<br>function EnumWindowsProc(hwnd: cardinal; lParam: integer) : LongBool; stdcall;<br>var pwl &nbsp; &nbsp; &nbsp; : ^TWindowList;<br>&nbsp; &nbsp; i1 &nbsp; &nbsp; &nbsp; &nbsp;: integer;<br>&nbsp; &nbsp; cpid,ctid : cardinal;<br>&nbsp; &nbsp; cpar,cown : cardinal;<br>&nbsp; &nbsp; bvis,btsk : boolean;<br>begin<br>&nbsp; result:=true;<br>&nbsp; ctid:=GetWindowThreadProcessID(hwnd,@cpid);<br>&nbsp; if ((ew_pid=0) or (ew_pid=cpid)) and ((ew_tid=0) or (ew_tid=ctid)) then begin<br>&nbsp; &nbsp; bvis:=IsWindowVisible(hwnd);<br>&nbsp; &nbsp; cown:=GetWindow(hwnd,GW_OWNER); cpar:=GetParent(hwnd);<br>&nbsp; &nbsp; btsk:=(cown=0) and (cpar=0) and bvis and (GetWindowLong(hwnd,GWL_EXSTYLE) and WS_EX_TOOLWINDOW=0);<br>&nbsp; &nbsp; if (not ew_onlyThoseInTaskbar) or btsk then begin<br>&nbsp; &nbsp; &nbsp; pwl:=pointer(lParam);<br>&nbsp; &nbsp; &nbsp; i1:=length(pwl^);<br>&nbsp; &nbsp; &nbsp; SetLength(pwl^,i1+1);<br>&nbsp; &nbsp; &nbsp; with pwl^[i1] do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; window:=hwnd;<br>&nbsp; &nbsp; &nbsp; &nbsp; parent:=cpar; owner:=cown;<br>&nbsp; &nbsp; &nbsp; &nbsp; visible:=bvis; enabled:=IsWindowEnabled(hwnd);<br>&nbsp; &nbsp; &nbsp; &nbsp; inTaskbar:=btsk;<br>&nbsp; &nbsp; &nbsp; &nbsp; GetWindowRect(hwnd,rect);<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(title,MAX_PATH);<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(title,GetWindowText(hwnd,pchar(title),MAX_PATH));<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(className,MAX_PATH);<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(className,GetClassName(hwnd,pchar(className),MAX_PATH));<br>&nbsp; &nbsp; &nbsp; &nbsp; pid:=cpid; tid:=ctid;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>function GetWindowList(pid: cardinal = 0; tid: cardinal = 0; onlyThoseInTaskbar: boolean = false) : TWindowList;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; ew_pid:=pid; ew_tid:=tid; ew_onlyThoseInTaskbar:=onlyThoseInTaskbar;<br>&nbsp; if ew_tid=0 then EnumWindows &nbsp; &nbsp; &nbsp;( &nbsp; &nbsp; &nbsp; @EnumWindowsProc,integer(@result))<br>&nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EnumThreadWindows(ew_tid,@EnumWindowsProc,integer(@result));<br>end;<br><br>function GetChildWindowList(window: cardinal) : TWindowList;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; ew_pid:=0; ew_tid:=0; ew_onlyThoseInTaskbar:=false;<br>&nbsp; EnumChildWindows(window,@EnumWindowsProc,integer(@result));<br>end;<br><br>function EnumWindowStationsProc(windowStationName: pchar; lParam: integer) : LongBool; stdcall;<br>var i1 &nbsp; : integer;<br>&nbsp; &nbsp; pwsl : ^TWindowStationList;<br>begin<br>&nbsp; result:=true;<br>&nbsp; pwsl:=pointer(lParam);<br>&nbsp; i1:=length(pwsl^);<br>&nbsp; SetLength(pwsl^,i1+1);<br>&nbsp; pwsl^[i1].name:=windowStationName;<br>end;<br><br>function GetWindowStationList(desktopsToo: boolean = false; windowsToo: boolean = false) : TWindowStationList;<br>var c1 : cardinal;<br>&nbsp; &nbsp; i1 : integer;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; EnumWindowStations(@EnumWindowStationsProc,integer(@result));<br>&nbsp; if desktopsToo then<br>&nbsp; &nbsp; for i1:=0 to high(result) do begin<br>&nbsp; &nbsp; &nbsp; c1:=OpenWindowStation(pchar(result[i1].name),false,WINSTA_ENUMDESKTOPS);<br>&nbsp; &nbsp; &nbsp; if c1&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].desktops:=GetDesktopList(c1,windowsToo);<br>&nbsp; &nbsp; &nbsp; &nbsp; finally CloseWindowStation(c1) end;<br>&nbsp; &nbsp; end;<br>end;<br><br>function EnumDesktopsProc(desktopName: pchar; lParam: integer) : LongBool; stdcall;<br>var i1 &nbsp;: integer;<br>&nbsp; &nbsp; pdl : ^TDesktopList;<br>begin<br>&nbsp; result:=true;<br>&nbsp; pdl:=pointer(lParam);<br>&nbsp; i1:=length(pdl^);<br>&nbsp; SetLength(pdl^,i1+1);<br>&nbsp; pdl^[i1].name:=desktopName;<br>end;<br><br>function GetDesktopList(ws: cardinal = 0; windowsToo: boolean = false) : TDesktopList;<br>var c1 : cardinal;<br>&nbsp; &nbsp; i1 : integer;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; if ws=0 then ws:=GetProcessWindowStation;<br>&nbsp; EnumDesktops(ws,@EnumDesktopsProc,integer(@result));<br>&nbsp; if windowsToo then <br>&nbsp; &nbsp; for i1:=0 to high(result) do begin<br>&nbsp; &nbsp; &nbsp; c1:=OpenDesktop(pchar(result[i1].name),0,false,DESKTOP_READOBJECTS);<br>&nbsp; &nbsp; &nbsp; if c1&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i1].windows:=GetDesktopWindowList(c1);<br>&nbsp; &nbsp; &nbsp; &nbsp; finally CloseDesktop(c1) end;<br>&nbsp; &nbsp; end;<br>end;<br><br>function GetDesktopWindowList(dt: cardinal = 0) : TWindowList;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; if dt=0 then dt:=GetThreadDesktop(GetCurrentThreadID);<br>&nbsp; ew_pid:=0; ew_tid:=0; ew_onlyThoseInTaskbar:=false;<br>&nbsp; EnumDesktopWindows(dt,@EnumWindowsProc,integer(@result));<br>end;<br><br>{Button The class for a button.<br>ComboBox The class for a combo box.<br>Edit The class for an edit control.<br>ListBox The class for a list box.<br>MDIClient The class for an MDI client window.<br>ScrollBar The class for a scroll bar.<br>Static The class for a static control.<br><br><br>The following table describes the system classes that are available only for use by the system. They are listed here for completeness sake.<br><br>Class Description<br>ComboLBox The class for the list box contained in a combo box.<br>DDEMLEvent Windows NT: The class for DDEML events.<br>Message Windows NT 5.0 and later: The class for a message-only window.<br>#32768 The class for a menu.<br>#32769 The class for the desktop window.<br>#32770 The class for a dialog box.<br>#32771 The class for the task switch window.<br>#32772 Windows NT: The class for icon titles. &nbsp;}<br><br>type TPasswordCacheEntry &nbsp;= packed record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry &nbsp; &nbsp; &nbsp; : word; &nbsp; // size of this entry, in bytes<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resourceLen : word; &nbsp; // size of resource name, in bytes<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; passwordLen : word; &nbsp; // size of password, in bytes<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entryIndex &nbsp;: byte; &nbsp; // entry index<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entryType &nbsp; : byte; &nbsp; // type of entry<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resource &nbsp; &nbsp;: array [0..$FFFFFFF] of char;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // start of resource name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // password immediately follows resource name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;TPPasswordCacheEntry = ^TPasswordCacheEntry;<br><br>function EnumPasswordCallbackProc(pce: TPPasswordCacheEntry; lParam: cardinal) : LongBool; stdcall;<br>var i1 &nbsp; : integer;<br>&nbsp; &nbsp; ppcl : ^TCachedPasswordList;<br>begin<br>&nbsp; result:=true;<br>&nbsp; ppcl:=pointer(lParam);<br>&nbsp; i1:=length(ppcl^);<br>&nbsp; SetLength(ppcl^,i1+1);<br>&nbsp; SetLength(ppcl^[i1].resource,pce^.resourceLen);<br>&nbsp; Move(pce^.resource[0],pointer(ppcl^[i1].resource)^,pce^.resourceLen);<br>&nbsp; ppcl^[i1].resource:=pchar(ppcl^[i1].resource);<br>&nbsp; SetLength(ppcl^[i1].password,pce^.passwordLen);<br>&nbsp; Move(pce^.resource[pce^.resourceLen],pointer(ppcl^[i1].password)^,pce^.passwordLen);<br>&nbsp; ppcl^[i1].password:=pchar(ppcl^[i1].password);<br>&nbsp; ppcl^[i1].resType:=pce^.entryType;<br>end;<br><br>var WNetEnumCachedPasswords : function (ps: pchar; pw: word; pb: byte; proc: pointer; lParam: cardinal) : word; stdcall<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = nil;<br>&nbsp; &nbsp; mpr &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : cardinal = 0;<br><br>function GetCachedPasswords : TCachedPasswordList;<br>begin<br>&nbsp; result:=nil;<br>&nbsp; if mpr=0 then begin<br>&nbsp; &nbsp; mpr:=LoadLibrary('mpr');<br>&nbsp; &nbsp; if mpr=0 then exit;<br>&nbsp; end;<br>&nbsp; if @WNetEnumCachedPasswords=nil then begin<br>&nbsp; &nbsp; WNetEnumCachedPasswords:=GetProcAddress(mpr,'WNetEnumCachedPasswords');<br>&nbsp; &nbsp; if @WNetEnumCachedPasswords=nil then exit;<br>&nbsp; end;<br>&nbsp; WNetEnumCachedPasswords(nil,0,$FF,@EnumPasswordCallbackProc,cardinal(@result));<br>end;<br><br>initialization<br>finalization<br>&nbsp; if mpr &nbsp; &nbsp; &nbsp; &nbsp;&lt;&gt;0 then FreeLibrary(mpr &nbsp; &nbsp; &nbsp; &nbsp;);<br>// &nbsp;if psApiHandle&lt;&gt;0 then FreeLibrary(psApiHandle);<br>end.<br><br>
 
我收集的资料,根据这些,我自己做的工具完全正常!<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1424855
 
多谢两位
 
多人接受答案了。
 
后退
顶部