uses
TLHelp32,PsAPI;
(1)显示进程列表:

 procedure TForm1.Button2Click(Sender: TObject);
var
lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
P:DWORD;
s:string;
begin
ListBox1.Items.Clear ;
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,);
found := Process32First(Hand,lppe);
while found do
begin
s := StrPas(lppe.szExeFile);
if lppe.th32ProcessID> then
p := lppe.th32ProcessID
else
p := ;
ListBox1.Items.AddObject(s,pointer(p));//列出所有进程。
found := Process32Next(Hand,lppe);
end;
end;

(2)杀死某进程:

 procedure TForm1.Button3Click(Sender: TObject);
var
lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
P:DWORD;
sExeFile,sSelect:string;
killed:boolean;
begin
p :=DWORD(ListBox1.Items.Objects[ListBox1.itemindex]);
if P<> then
begin
killed := TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF);
if not killed then
messagebox(self.handle,pchar(sExeFile+'无法杀死!'),'提示',MB_OK or MB_ICONWARNING)
else
ListBox1.Items.Delete(ListBox1.ItemIndex);
end;
end;

(3)取得某进程EXE路径:

procedure TForm1.Button8Click(Sender: TObject); //uses PSAPI;
var
h:THandle;
fileName:string;
iLen:integer;
hMod:HMODULE;
cbNeeded,p:DWORD;
begin
p :=DWORD(ListBox1.Items.Objects[ListBox1.itemindex]);
h := OpenProcess(PROCESS_ALL_ACCESS, false, p); //p 为 进程ID
if h > then
begin
if EnumProcessModules( h, @hMod, sizeof(hMod), cbNeeded) then
begin
SetLength(fileName, MAX_PATH);
iLen := GetModuleFileNameEx(h, hMod, PCHAR(fileName), MAX_PATH);
if iLen <> then
begin
SetLength(fileName, StrLen(PCHAR(fileName)));
ShowMessage(fileName);
end;
end;
CloseHandle(h);
end;
end;

(4)取得窗口列表:

begin
ListBox1.Items.Clear ;
EnumWindows(@EnumWindowsProc, );
end;

(5)杀死窗口进程:

procedure TForm1.Button6Click(Sender: TObject);
var
H:THandle;
P:DWORD;
s:string;
killed:boolean;
begin
s := ListBox1.Items[ListBox1.ItemIndex];
H:=FindWindow(nil,pchar(s));
if H<> then
begin
GetWindowThreadProcessId(H,@P);
if P<> then
killed:=TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF);
if not killed then
messagebox(self.handle,pchar(s+'无法杀死!'),'提示',MB_OK or MB_ICONWARNING)
else
ListBox1.Items.Delete(ListBox1.ItemIndex);
end;
end;

(6)取得窗口进程路径:

procedure TForm1.Button9Click(Sender: TObject);
var
H:THandle;
P,cbNeeded: DWORD;
s,fileName:string;
iLen:integer;
hMod:HMODULE;
begin
s := ListBox1.Items[ListBox1.ItemIndex];
H:=FindWindow(nil,pchar(s));
if H<> then
begin
GetWindowThreadProcessId(H,@P);
if P<> then
begin
h := OpenProcess(PROCESS_ALL_ACCESS, false, p); //p 为 进程ID
if h > then
begin
if EnumProcessModules( h, @hMod, sizeof(hMod), cbNeeded) then
begin
SetLength(fileName, MAX_PATH);
iLen := GetModuleFileNameEx(h, hMod, PCHAR(fileName), MAX_PATH);
if iLen <> then
begin
SetLength(fileName, StrLen(PCHAR(fileName)));
ShowMessage(fileName);
end;
end;
CloseHandle(h);
end;
end;
end;
end;

(7)文件属性:

procedure TForm1.Button1Click(Sender: TObject);
var
SR: TSearchRec;
V1, V2, V3, V4: integer ;
const
dtFmt:string = 'YYYY-MM-DD HH:NN:SS';
begin
// ============== 方法一 ==================== //
if FindFirst(sFileName, faAnyFile, SR) = then
begin
Edit1.Text := intToStr(SR.Attr); //文件属性
Edit2.Text := intToStr(SR.Size); //文件大小
Edit3.Text := FormatDateTime(dtFmt,CovFileDate(SR.FindData.ftCreationTime)); //创建时间
Edit4.Text := FormatDateTime(dtFmt,CovFileDate(SR.FindData.ftLastWriteTime)); //最后修改时间
Edit5.Text := FormatDateTime(dtFmt,CovFileDate(SR.FindData.ftLastAccessTime)); //最后访问时间
if SR.Attr and faHidden <> then
FileSetAttr(sFileName, SR.Attr-faHidden);
FindClose(SR);
end;
if GetFileVersion(sFileName,V1, V2, V3, V4) then
Edit7.Text := intToStr(v1)+'.'+intToStr(v2)+'.'+intToStr(v3)+'.'+intToStr(v4);
// ============== 方法二 ==================== //
{
var
Attrs: Word;
f: file of Byte; // 文件大小 必须要 定义为" file of byte" ,这样才能取出 bytes
size: Longint;
//begin
//文件属性
Attrs := FileGetAttr(sFileName);
Edit1.Text := intToStr(Attrs);
//文件大小
AssignFile(f, OpenDialog1.FileName);
Reset(f);
try
AssignFile(f, sFileName);
Reset(f);
size := FileSize(f);
Edit2.Text := intToStr(size);
finally
CloseFile(f);
end;
}
end;

(8)判断程序是否在运行:

procedure TForm1.Button5Click(Sender: TObject);
var
PrevInstHandle:Thandle;
AppTitle:pchar;
begin
AppTitle := pchar('test');
PrevInstHandle := FindWindow(nil, AppTitle);
if PrevInstHandle <> then
begin
if IsIconic(PrevInstHandle) then
ShowWindow(PrevInstHandle, SW_RESTORE)
else
BringWindowToTop(PrevInstHandle);
SetForegroundWindow(PrevInstHandle);
end;
end;

获取进程列表

ListView1.Items.BeginUpdate;
ListView1.Items.Clear;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, );
// CreateToolhelp32Snapshot函数得到进程快照
FProcessEntry32.dwSize := SizeOf(FProcessEntry32); // 初始化
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
// Process32First 得到一个系统快照里第一个进程的信息
Summ := ;
while ContinueLoop do
begin
Summ := Summ + ;
NewItem := ListView1.Items.Add; // 在ListView1显示
NewItem.ImageIndex := -;
NewItem.Caption := ExtractFileName(FProcessEntry32.szExeFile); // 进程名称
// ??NewItem.Caption := ExtractFilePath(FProcessEntry32.szExeFile);//进程名称
NewItem.subItems.Add(FormatFloat('', Summ)); // 序号
NewItem.subItems.Add(IntToStr(FProcessEntry32.th32ProcessID)); // 进程ID
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
ListView1.Items.EndUpdate;
Label1.Caption := '进程数:' + IntToStr(ListView1.Items.count);
ShowMessage(GetPathFileofModule('explorer.exe'));
ShowMessage(GetProcessPath());

Delphi 获取系统当前进程、窗口句柄、文件属性以及程序运行状态的更多相关文章

  1. Delphi编程获取系统当前进程、窗口句柄、文件属性以(转)

    Delphi编程获取系统当前进程.窗口句柄.文件属性以及程序运行状态. uses TLHelp32,PsAPI; (1)显示进程列表:procedure TForm1.Button2Click(Sen ...

  2. Android开发之获取系统所有进程信息。

    最近在做一个app,有一个进程管理模块用于管理系统中正在运行的进程,并且可以关闭进程进行加速手机的功能,基本把它实现了出来.界面的效果都是自己写的,虽然有BUG,但是基本上能满足需求,后期我会改进BU ...

  3. Android 5.0以上获取系统运行进程信息

    在Android 5.0以上系统,调用getRunningAppProcesses 方法返回的列表为空,这是因为谷歌考虑到安全原因,已经把这个方法移除掉了, 那以后要获取系统运行的后台进程这个方法用不 ...

  4. Delphi 获取系统的语言环境参数GetSystemDefaultLangID、VerLanguageName、GetLocaleInfo

    1 核心的两个API函数:GetSystemDefaultLangID 和 VerLanguageName. GetSystemDefaultLangID:获得系统默认语言的ID VerLanguag ...

  5. Delphi 获取系统时间后格式化输出

    问题:客户现场程序运行提示时间格式不对导致的错误,原因是与开发环境及公司内部测试环境的日期格式不一致: 解决:统一强制转换: //引用单元:SysUtils //目的:实现跨环境兼容不同日期格式,如果 ...

  6. delphi 获取系统注册的文件图标

    var Icon:TICON; Key : string; App : string; Index : Integer; begin FileName:=Edit6.Text; then begin ...

  7. Linux下的C程序如何调用系统命令,并获取系统的输出信息到C程序中

    直接贴代码: #include <stdio.h> #include <string.h> #include <errno.h> int main(int argc ...

  8. 获取系统中所有进程&线程信息

    读书笔记--[计算机病毒解密与对抗] 目录: 遍历进程&线程程序 终止进程 获取进程信息 获取进程内模块信息 获取进程命令行参数 代码运行环境:Win7 x64 VS2012 Update3 ...

  9. Delphi 获取进程路径及命令行参数

    Delphi 获取进程路径及命令行参数, 但有的进程获取时会报错,不知为啥 type PVOID64 = UINT64; _UNICODE_STRING = packed record Length ...

随机推荐

  1. 最新最全最详细的MacOS 10.14 Mojave黑苹果安装教程

    图文教程知乎地址:点击打开链接 视频教程B站地址:点击打开链接 微信公众号 地 址:点击打开链接 准备工作(工具包及镜像在后边) 一个8G以上的U盘(有的U盘标的是8G,实际只有7.X,实际容量小于7 ...

  2. delphi 获取系统注册的文件图标

    var Icon:TICON; Key : string; App : string; Index : Integer; begin FileName:=Edit6.Text; then begin ...

  3. mapreduce求共同好友

    逻辑分析 以下是qq的好友列表数据,冒号前是一个用户,冒号后是该用户的所有好友(数据中的好友关系是单向的) A:B,C,D,F,E,O B:A,C,E,K C:F,A,D,I D:A,E,F,L E: ...

  4. Comet OJ 三元组 推导+两个指针+分类讨论

    题目:https://www.cometoj.com/contest/59/problem/F?problem_id=2681 题意:给你n个三元组 ai,bi,ci,如果某一对三元组满足    2* ...

  5. Spring学习笔记第一篇——初识Spring

    1.简单介绍 spring的ioc底层是先配置xml文件,接着创建工厂,利用dom4j解析配置文件,最后通过反射完成.大概步骤差不多这样,这些具体代码spring帮你完成了.现在我们只需要配置xml和 ...

  6. react jsx 中使用 switch case 示例

    <div> <span>适用平台:</span> <span>{(() => { switch (currentItems.usePlatform ...

  7. sql审核工具调研安装-sqlAdvisor和soar

    sql审核工具调研  基于soar的sql审核查询平台: https://github.com/beiketianzhuang/data-platform-soar 1.美团工具sqlAdvisor工 ...

  8. Linux中的特殊权限s、t、i、a

    文件权限除了r.w.x外还有s.t.i.a权限:s:文件属主和组设置SUID和GUID,文件在被设置了s权限后将以root身份执行.在设置s权限时文件属主.属组必须先设置相应的x权限,否则s权限并不能 ...

  9. Nginx网络架构实战学习笔记(四):nginx连接memcached、第三方模块编译及一致性哈希应用

    文章目录 nginx连接memcached 第三方模块编译及一致性哈希应用 总结 nginx连接memcached 首先确保nginx能正常连接php location ~ \.php$ { root ...

  10. 高级UI晋升之自定义view实战(七)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章自定义ViewGroup实现瀑布流效果来进行详解dispatchTouch ...