问题描述
我想在Windows任务管理器的应用程序选项卡(而不是进程选项卡)中运行并显示的程序列表,并在HDD上获取其位置?我需要在Delphi中完成。任何人都可以帮助?据我所知,任务管理器中的应用程序选项卡是顶级窗口的列表,不属于其他窗口,没有父级,而不是工具窗口。在我的中,我有一个名为AppInfo.pas的单位,返回具有这种特性的窗口列表,并且列表与您在任务管理器中看到的匹配。这是编写EnumWindows API函数的回调函数的代码的主要部分:
{$ IFDEF DELPHI2007UP }
类函数TAppWindowCollection.EnumWinProc(wHandle:HWND; lparam:integer):Bool;
{$ ELSE}
函数EnumWinProc(wHandle:HWND; lparam:integer):Bool;标准
{$ ENDIF}
Const
MAX_TEXT = MAX_PATH;
var
WindowItem:TWindowItem;
strText,strClass:array [0..MAX_TEXT] of char;
IsAppMainWin:Boolean;
begin
//检查窗口是否是可视应用程序主窗口。
IsAppMainWin:= IsWindowVisible(wHandle)AND //可见
(GetWindow(wHandle,GW_OWNER)= 0)AND //不由其他窗口拥有
(GetParent(wHandle)= 0)AND //没有任何父
(GetWindowLong(wHandle,GWL_EXSTYLE)AND WS_EX_TOOLWINDOW = 0); //不是工具窗口
如果IsAppMainWin然后
begin
WindowItem:= TAppWindowCollection(lparam).Add;
GetWindowText(wHandle,strText,MAX_TEXT);
GetClassName(wHandle,strClass,MAX_TEXT);
WindowItem.FCaption:= strText;
WindowItem.FHandle:= wHandle;
WindowItem.FWindowClass:= strClass;
GetWindowThreadProcessId(wHandle,WindowItem.FProcessID);
结束
结果:= True;
结束
有关完整的源代码,可以参考。
这些只是窗口。如果要获取对应于每个项目的EXE文件的路径,您应该首先使用 API函数。这就是我在上面的代码中所做的。一旦拥有进程ID,就可以从中获取一个进程句柄,并枚举它的模块。第一个模块是主EXE文件。我在我的TProcessInfo组件中实现了它,它与AppInfo.pas包含在同一个包中。
关心
I would like to get list of programs running and visible in windows task manager's Applications Tab (not processes tab) and get their locations on HDD ? I need it to be done in Delphi. Anybody can help ?
As far as I know, Application tab in Task Manager is a list of top-level windows which are not owned by other windows, have no parent, and are not tool windows. In my Process Info, I have a unit called AppInfo.pas which returns a list of windows with such characteristics, and the list matches what you see in Task Manager. Here is the main part of the code which is written as a call-back function for EnumWindows API function:
{$IFDEF DELPHI2007UP}
class function TAppWindowCollection.EnumWinProc(wHandle: HWND; lparam: integer): Bool;
{$ELSE}
function EnumWinProc(wHandle: HWND; lparam: integer): Bool; stdcall;
{$ENDIF}
Const
MAX_TEXT = MAX_PATH;
var
WindowItem : TWindowItem;
strText,strClass : array [0..MAX_TEXT] of char;
IsAppMainWin : Boolean;
begin
//Check if the window is a visible application main window.
IsAppMainWin := IsWindowVisible(wHandle) AND //Visible
(GetWindow(wHandle,GW_OWNER) = 0) AND //Not owned by other windows
(GetParent(wHandle) = 0) AND //Does not have any parent
(GetWindowLong(wHandle,GWL_EXSTYLE) AND WS_EX_TOOLWINDOW = 0); //Not a tool window
if IsAppMainWin then
begin
WindowItem := TAppWindowCollection(lparam).Add;
GetWindowText(wHandle,strText,MAX_TEXT);
GetClassName(wHandle,strClass,MAX_TEXT);
WindowItem.FCaption := strText;
WindowItem.FHandle := wHandle;
WindowItem.FWindowClass := strClass;
GetWindowThreadProcessId(wHandle,WindowItem.FProcessID);
end;
Result := True;
end;
For the full source code, you can refer to AppInfo.pas.
These are just windows. If you want to get path of EXE file corresponding to each item, you should first find the process which is owning this window, using GetWindowThreadProcessID API function. That is what I did in the above code. Once you have the process ID, you can get a process handle from it, and enumerate its modules. The first module is the main EXE file. I implemented that in my TProcessInfo component which is included in the same package with AppInfo.pas.
Regards
这篇关于如何从Windows任务管理器(应用程序选项卡)+他们在德尔福的硬盘上的位置获取应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!