delphi function 检查进程是否存在,最好写一个function,我拿来直接用。

 我来答
百度网友b21ba69cc
2011-07-01 · TA获得超过210个赞
知道小有建树答主
回答量:114
采纳率:0%
帮助的人:97.7万
展开全部
procedure TfrmMain.FormShow(Sender: TObject);
var
i:integer;
date1,sqlstr:string;
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
Ret : BOOL;
ProcessHndle : THandle;
ProcessID : integer;
s:string;
bt:int64;
findflag:boolean;
reg:tregistry;
begin
bt:=gettickcount();
while ((gettickcount()-20000)<bt)and not findflag do
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
Ret:=Process32First(FSnapshotHandle,FProcessEntry32);
ProcessID:=FProcessEntry32.th32ProcessID;
while Ret do
begin
s:=ExtractFileName(FProcessEntry32.szExeFile);
Ret:=Process32Next(FSnapshotHandle,FProcessEntry32);
if lowercase(trim(s))='sqlservr.exe' then
begin
findflag:=true;
break;
end;
end;
CloseHandle(FSnapshotHandle);
ProcessHndle:=OpenProcess(PROCESS_VM_WRITE,false,ProcessID);
CloseHandle(ProcessHndle);
application.ProcessMessages;
end;
if not findflag then
begin
if application.MessageBox('衡粗SQL Server服务器没有运行,请启动誉拦氏庆散后重新进入程序','信息提示',16)=idok then
application.Terminate;
end;
end;
这是我程序里检测SQlserver进程的。
更多追问追答
追问
贴到我的程序你无法使用。
追答
在uses中增加TLHelp32
windblast
2011-07-09 · 知道合伙人软件行家
windblast
知道合伙人软件行家
采纳数:5633 获赞数:13621
毕业于空军第一航空学院电子专业,1991年开始接触电脑,从事多年计算机编程,具有较丰富的经验。

向TA提问 私信TA
展开全部
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, PsAPI, TlHelp32, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

const
RsSystemIdleProcess = 'System Idle Process';
RsSystemProcess = 'System Process';

var
Form1: TForm1;

implementation

{$R *.dfm}

function IsWinXP: Boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
(Win32MajorVersion = 5) and (Win32MinorVersion = 1);
end;

function IsWin2k: Boolean;
begin
Result := (Win32MajorVersion >= 5) and
(Win32Platform = VER_PLATFORM_WIN32_NT);
end;

function IsWinNT4: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 4);
end;

function IsWin3X: Boolean;
begin
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
Result := Result and (Win32MajorVersion = 3) and
((Win32MinorVersion = 1) or (Win32MinorVersion = 5) or
(Win32MinorVersion = 51));
end;

function InRunningProcesses(const FileName:String ; FullPath: Boolean): Boolean;

function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := ' ';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
if FullPath then
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := ' ';
end
else
begin
if GetModuleBaseNameA(Handle, 0, PAnsiChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := ' ';
end;
finally
CloseHandle(Handle);
end;
end;

function InListTH: Boolean;
var
SnapProcHandle: THandle;
ProcEntry: TProcessEntry32;
NextProc: Boolean;
LocalFileName: string;
LocalResult:boolean;
begin
Result:=false;
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
LocalResult := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if LocalResult then
try
ProcEntry.dwSize := SizeOf(ProcEntry);
NextProc := Process32First(SnapProcHandle, ProcEntry);
while NextProc do
begin
if ProcEntry.th32ProcessID = 0 then
begin
// PID 0 is always the "System Idle Process " but this name cannot be
// retrieved from the system and has to be fabricated.
LocalFileName := RsSystemIdleProcess;
end
else
begin
if IsWin2k or IsWinXP then
begin
LocalFileName := ProcessFileName(ProcEntry.th32ProcessID);
if LocalFileName = ' ' then
LocalFileName := ProcEntry.szExeFile;
end
else
begin
LocalFileName := ProcEntry.szExeFile;
if not FullPath then
LocalFileName := ExtractFileName(LocalFileName);
end;
end;
if UpperCase(LocalFileName)=UpperCase(FileName) then
begin
Result:=true;
Exit;
end;
NextProc := Process32Next(SnapProcHandle, ProcEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;
end;

function InListPS: Boolean;
var
PIDs: array [0..1024] of DWORD;
Needed: DWORD;
I: Integer;
LocalFileName: string;
EnumResult:Boolean;
begin
Result:=false;
EnumResult := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
if EnumResult then
begin
for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
begin
case PIDs[I] of
0:
// PID 0 is always the "System Idle Process " but this name cannot be
// retrieved from the system and has to be fabricated.
LocalFileName := RsSystemIdleProcess;
2:
// On NT 4 PID 2 is the "System Process " but this name cannot be
// retrieved from the system and has to be fabricated.
if IsWinNT4 then
LocalFileName := RsSystemProcess
else
LocalFileName := ProcessFileName(PIDs[I]);
8:
// On Win2K PID 8 is the "System Process " but this name cannot be
// retrieved from the system and has to be fabricated.
if IsWin2k or IsWinXP then
LocalFileName := RsSystemProcess
else
LocalFileName := ProcessFileName(PIDs[I]);
else
LocalFileName := ProcessFileName(PIDs[I]);
end;
if UpperCase(LocalFileName) = UpperCase(FileName) then
begin
Result:=true;
Exit;
end;
end;
end;
end;
begin
if IsWin3X or IsWinNT4 then
Result := InListPS
else
Result := InListTH;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if InRunningProcesses( 'c:\windows\notepad.exe',true) then
Caption:= 'True '
else
Caption:= 'false ';
end;

end.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
手机用户26340
2011-06-30 · TA获得超过202个赞
知道答主
回答量:437
采纳率:0%
帮助的人:0
展开全部
首先,从一个程序里读取另一个程序里的巧哗数据,只能使用地址,不过你可以在自己的程序橘宽桥里给这个圆猛地址取个名字。
典型应用,自己写个程序,读别的程序里的密码框里的东西?
你可以搜索怎么写木马,具体就太罗嗦了
追问
我没那么龌龊,我只是想检测一个进程是否存在,然后显示不同的提示而已。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式