怎么判断exe是否被打开 怎么判断 c:\aa.exe是否被打开? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码如下// 获取系统当前进程名和进程ID,//注:应引用"TLHelp32"单元"use TLHelp32"。unit Unit2;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, ComCtrls, StdCtrls,TLHelp32;typeTForm2 = class(TForm) ListBox1: TListBox; ListView1: TListView; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);private { Private declarations }public { Public declarations }end;varForm2: TForm2;ContinueLoop:BOOL; //是否继续循环FSnapshotHandle:THandle; //进程快照句柄FProcessEntry32:TProcessEntry32; //进程入口的结构体信息implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);//在listview中显示进程varNewItem: TListItem;Summ:integer;beginListView1.Items.BeginUpdate;ListView1.Items.Clear;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//CreateToolhelp32Snapshot函数得到进程快照FProcessEntry32.dwSize := Sizeof(FProcessEntry32); //初始化ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);//Process32First 得到一个系统快照里第一个进程的信息Summ := 0;while ContinueLoop do begin Summ := Summ + 1; NewItem := ListView1.Items.Add; //在ListView1显示 NewItem.ImageIndex := -1; NewItem.Caption := ExtractFileName(FProcessEntry32.szExeFile); //进程名称 //??NewItem.Caption := ExtractFilePath(FProcessEntry32.szExeFile);//进程名称 NewItem.subItems.Add(FormatFloat('00', Summ));//序号 NewItem.subItems.Add(IntToStr(FProcessEntry32.th32ProcessID));//进程ID ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);end;CloseHandle(FSnapshotHandle);ListView1.Items.EndUpdate;Label1.Caption:='进程数:'+inttostr(ListView1.Items.Count);end;procedure TForm2.Button2Click(Sender: TObject);//在listbox中显示进程 idvarProcessName : string; //进程名ProcessID : integer; //进程表示符beginFSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); //创建一个进程快照FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32); //得到系统中第一个进程//循环例举while ContinueLoop dobegin ProcessName := FProcessEntry32.szExeFile; ProcessID := FProcessEntry32.th32ProcessID; Listbox1.Items.add('应用程序名 :'+ProcessName +'#进程ID:'+ inttostr(ProcessID)); ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);end;end;procedure TForm2.FormCreate(Sender: TObject);begin//对ListView1的初始化ListView1.ViewStyle:=vsReport; //设置ListView的显示方式 不设置这种方式不显示列头ListView1.Columns.Add; //添加第一列ListView1.Column[0].Caption:='进程名';ListView1.Column[0].AutoSize:=false;ListView1.Column[0].Width:=100;ListView1.Column[0].Alignment:=taLeftJustify;//左对齐ListView1.Columns.Add; //添加第二列ListView1.Column[ListView1.Columns.Count-1].Caption:='序号';ListView1.Column[ListView1.Columns.Count-1].AutoSize:=true;ListView1.Column[ListView1.Columns.Count-1].Alignment:=taLeftJustify;//左对齐ListView1.Columns.Add; //添加第三列ListView1.Column[ListView1.Columns.Count-1].Caption:='ID';ListView1.Column[ListView1.Columns.Count-1].AutoSize:=true;ListView1.Column[ListView1.Columns.Count-1].Alignment:=taLeftJustify;//左对齐end;end. 主要是查找进程CreateToolhelp32Snapshot 句柄是一方面,另一方面你可以直接写入EXE,写入不成功就证明他正在运行不过这方法比较危险,一般不提倡使用 不是有个简单的API函数可以直接获得程序名字,返回就说明已经打开,找不到就说明没有打开,前提该程序最好取个特殊名字,避免和前提程序同名,不需要那么多代码 主要是查找进程CreateToolhelp32Snapshot try 删除之 从回收站还原。except 使用中end 寻wsocket控件 dcu文件或pas文件 报表制作与打印 一个非常头疼的flash播放问题!!! 帮帮我吧,不懂啊! 一个关于DBCombobox的问题,很简单的! 请各位帮个忙,FileAge()、raise是什么意思?虽然是简单希望各位帮忙!! 到底数据库中应该不应该用ID来唯一标识一条记录……烦人啊!散分…… 太菜了,有分 delphi 2006 .ocx 安装 小問題,幫幫忙!如何設定 dbgrid 每一行的高度 插入的问题 delphi程序中unicode小问题
//注:应引用"TLHelp32"单元"use TLHelp32"。
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,TLHelp32;type
TForm2 = class(TForm)
ListBox1: TListBox;
ListView1: TListView;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
ContinueLoop:BOOL; //是否继续循环
FSnapshotHandle:THandle; //进程快照句柄
FProcessEntry32:TProcessEntry32; //进程入口的结构体信息implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
//在listview中显示进程
var
NewItem: TListItem;
Summ:integer;
begin
ListView1.Items.BeginUpdate;
ListView1.Items.Clear;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
//CreateToolhelp32Snapshot函数得到进程快照
FProcessEntry32.dwSize := Sizeof(FProcessEntry32); //初始化
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
//Process32First 得到一个系统快照里第一个进程的信息
Summ := 0;
while ContinueLoop do
begin
Summ := Summ + 1;
NewItem := ListView1.Items.Add; //在ListView1显示
NewItem.ImageIndex := -1;
NewItem.Caption := ExtractFileName(FProcessEntry32.szExeFile); //进程名称
//??NewItem.Caption := ExtractFilePath(FProcessEntry32.szExeFile);//进程名称
NewItem.subItems.Add(FormatFloat('00', Summ));//序号
NewItem.subItems.Add(IntToStr(FProcessEntry32.th32ProcessID));//进程ID
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
ListView1.Items.EndUpdate;Label1.Caption:='进程数:'+inttostr(ListView1.Items.Count);end;procedure TForm2.Button2Click(Sender: TObject);
//在listbox中显示进程 id
var
ProcessName : string; //进程名
ProcessID : integer; //进程表示符
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); //创建一个进程快照
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32); //得到系统中第一个进程
//循环例举
while ContinueLoop do
begin
ProcessName := FProcessEntry32.szExeFile;
ProcessID := FProcessEntry32.th32ProcessID;
Listbox1.Items.add('应用程序名 :'+ProcessName +'#进程ID:'+ inttostr(ProcessID));
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;procedure TForm2.FormCreate(Sender: TObject);begin
//对ListView1的初始化
ListView1.ViewStyle:=vsReport; //设置ListView的显示方式 不设置这种方式不显示列头
ListView1.Columns.Add; //添加第一列
ListView1.Column[0].Caption:='进程名';
ListView1.Column[0].AutoSize:=false;
ListView1.Column[0].Width:=100;
ListView1.Column[0].Alignment:=taLeftJustify;//左对齐
ListView1.Columns.Add; //添加第二列
ListView1.Column[ListView1.Columns.Count-1].Caption:='序号';
ListView1.Column[ListView1.Columns.Count-1].AutoSize:=true;
ListView1.Column[ListView1.Columns.Count-1].Alignment:=taLeftJustify;//左对齐
ListView1.Columns.Add; //添加第三列
ListView1.Column[ListView1.Columns.Count-1].Caption:='ID';
ListView1.Column[ListView1.Columns.Count-1].AutoSize:=true;
ListView1.Column[ListView1.Columns.Count-1].Alignment:=taLeftJustify;//左对齐end;
end.
CreateToolhelp32Snapshot
不过这方法比较危险,一般不提倡使用
CreateToolhelp32Snapshot
删除之
从回收站还原。
except
使用中
end