我想获得在Windows任务管理器的应用程序选项卡(不处理选项卡)中运行并可见的程序列表并获取其在HDD上的位置?
我需要它在德尔福完成。任何人都可以帮忙?如何从Windows任务管理器(应用程序选项卡)获取应用程序+从德尔福在HDD上的位置
回答
据我所知,任务管理器中的“应用程序”选项卡是顶级窗口列表,它不属于其他窗口,没有父项,也不是工具窗口。在我的Process Info中,我有一个名为AppInfo.pas的单元,它返回具有这些特征的窗口列表,并且该列表与您在任务管理器中看到的内容相匹配。这里是一个被写成了EnumWindows的API函数的调用回调函数的代码的主要部分:
{$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;
对于完整的源代码,你可以参考AppInfo.pas。
,并得到他们的HDD
位置这些不仅仅是Windows。如果你想得到每个项目对应的EXE文件的路径,你应该首先使用GetWindowThreadProcessID API函数找到拥有这个窗口的过程。这就是我在上面的代码中所做的。一旦你有了进程ID,你可以从中获得一个进程句柄,并枚举它的模块。第一个模块是主EXE文件。我在我的TProcessInfo组件中实现了该组件,该组件与AppInfo.pas包含在同一个包中。
下面是一个完整独立的解决方案(没有更多的坏链接)
program ApplicationList;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Winapi.Windows,
Winapi.PsAPI;
function GetPathFromPID(const PID : cardinal) : string;
var
hProcess : THandle;
path : array [0 .. MAX_PATH - 1] of char;
begin
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
if hProcess <> 0
then
try
if GetModuleFileNameEx(hProcess, 0, path, MAX_PATH) = 0
then
RaiseLastOSError;
Result := path;
finally
CloseHandle(hProcess)
end
else
RaiseLastOSError;
end;
function EnumWinProc(wHandle : hWnd; lparam : integer) : Bool; stdcall;
Const
MAX_TEXT = MAX_PATH;
var
strText, strClass : array [0 .. MAX_TEXT] of char;
strPath : string;
IsAppMainWin : Boolean;
ProcId : cardinal;
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
GetWindowText(wHandle, strText, MAX_TEXT);
GetClassName(wHandle, strClass, MAX_TEXT);
GetWindowThreadProcessID(wHandle, ProcId);
try
strPath := GetPathFromPID(ProcId);
except
strPath := '???';
end;
WriteLn(ProcId, ' - ', strClass, ' - ', strText, ' - ', strPath);
end;
Result := True;
end;
procedure DoEnumWindows;
var
FirstWnd : cardinal;
begin
EnumWindows(@EnumWinProc, cardinal(@FirstWnd));
end;
begin
try
DoEnumWindows;
except
on E : Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.
不是真实可用的代码。我无法使用它 – Kermia 2013-01-07 12:45:47
@Kermia什么是不可用于此代码?它编译和检索所有想要的信息(德尔福XE3) – 2013-01-07 13:17:32
@Kermia - 应该怎么找出与你的评论代码有什么问题,我想知道.. – 2013-01-07 17:35:50
- 1. 获取Windows任务管理器应用程序选项卡
- 2. 从壳/ DOS应用程序获取输出到德尔福应用程序
- 3. 在任务管理器的应用程序选项卡中设置应用程序名称
- 4. 德尔福Web服务会从.NET MVC应用程序
- 5. Windows服务应用程序自卫德尔福(RAD工作室)
- 6. 德尔福Windows服务和WER(应用程序崩溃)
- 7. 德尔福VCL应用程序包
- 8. 德尔福应用程序运行
- 9. 德尔福应用程序挂起
- 10. 德尔福7:应用程序缩放
- 11. 如何从taskmanager的选项卡获取应用程序?
- 12. 如何从应用程序代理设置选项卡徽章
- 13. 如何防止从任务管理器关闭应用程序?
- 14. 获取任务管理器的应用程序选项卡中正在运行的任务列表
- 15. 德尔福OpenPictureDialog在Windows 10 在不同的应用程序
- 16. 在应用程序管理器选项卡中重命名Android应用程序
- 17. 获取德尔福MacOS的应用程序支持文件夹
- 18. 按下应用程序后,从任务管理器中删除应用程序
- 19. 德尔福6 IDE和应用程序在Windows 7 64位上工作?
- 20. 德尔福和Java应用程序 - 如何读取数据
- 21. 从应用程序的任何位置抓取服务(Android)
- 22. 从任务管理器处理退出应用程序
- 23. 管理从Windows服务的应用程序配置部分
- 24. Java/Windows获取应用程序位置
- 25. 获得德尔福TTimer与多线程应用程序
- 26. 发布到谷歌分析从德尔福应用程序
- 27. 德尔福 - 抓住所有action.onexecute从一个应用程序
- 28. 发送电子邮件从德尔福2007年应用程序
- 29. 德尔福2007年从应用程序拖动
- 30. 德尔福:如何获取Application.MainForm,如果应用程序是零(在DLL中)
感谢名单这么多! – chubbyk 2010-08-01 15:59:41
相关链接已过期! – Kermia 2013-01-06 15:50:38