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. 【多线程】ConcurrentLinkedQueue 的实现原理

    1. 引言 在并发编程中我们有时候需要使用线程安全的队列.如果我们要实现一个线程安全的队列有两种实现方式:一种是使用阻塞算法,另一种是使用非阻塞算法.使用阻塞算法的队列可以用一个锁(入队和出队用同一把 ...

  2. 开放融合 | “引擎级”深度对接!POLARDB与SuperMap联合构建首个云原生时空平台

    阿里巴巴新一代自研云数据库POLARDB与超图软件SuperMap GIS实现 “引擎级”深度对接,构建了自治.弹性.高可用的云原生时空数据管理平台联合解决方案,推出了业界首个“云原生数据库+云原生G ...

  3. 20150127 学军集训 day1

    day1 就直接考试... 和说好的不一样啊 第一题看都没怎么看就pass了,构造的题我一向没什么把握.然后瞟到第三题有30分可做,虽然要写的代码很大...反正我是写习惯了..期间纠结了一会还写了一个 ...

  4. 集合类中的Collection接口实现类

    今天学习一下集合包里面的内容,常见的有Collection和Map两个接口的实现类Collection中常见的又分为两种: 1.List ,支持放入重复的对象,实现类有arraylist,linked ...

  5. 常用github命令

    常用github命令 git--版本控制软件 GitHub是一个基于Git的远程文件托管平台(同GitCafe.BitBucket和GitLab等). 在家里,开发完毕部分功能,推送到GitHub:  ...

  6. commonJs的运行时加载和es6的编译时加载

    参考 : https://www.cnblogs.com/jerrypig/p/8145206.html 1.commonJs的运行时加载 2.ES6编译时加载

  7. Android的Context && 安卓常用系统服务(当前运行包名/当前网络状态和开关网络/音频服务/马达服务) (转)

    转:http://blog.csdn.net/zhandoushi1982/article/details/8501773 Context字面意思上下文,位于framework 的android.co ...

  8. 没有找到MSVCR110.dll,因此这个应用程序未能启动.重新安装应用程序可能会修复此问题

    问题: 在win7下用vs2012编译了一个exe放到xp上运行,弹出错误框"没有找到MSVCR110.dll,因此这个应用程序未能启动.重新安装应用程序可能会修复此问题" 解决办 ...

  9. VMware 安装CenterOS

    虚拟机安装CenterOS 简介:在VMware里安装Linux虚拟机,这里使用的是(Center OS 6.9). 一.准备工作: 安装 VMware Workstation Pro,很简单不哔哔了 ...

  10. 58、salesforce学习笔记(五)

    Set集合 Set<String> set1 = new Set<String>(); set1.add('1'); set1.add('2'); Set<String& ...