Post by GururI have an application .
I want that it should run only once.
How is it possible?
uses
Windows, Messages, SysUtils, Variants,
.........
ComCtrls, Tlhelp32,
.....
public
{ Public-Deklarationen }
function isProgrunning(programm:string):boolean;
.....
function TMainform.isProgrunning(programm:string):boolean;
var Snap : THandle;
ProcessE : TProcessEntry32;
i:integer;s1,s2 : string;
webstartcont : byte;
processes : tstrings;
begin
result:=false;
processes:=TStringList.Create;
Snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessE.dwSize:=SizeOf(ProcessE);
if Process32First(Snap,ProcessE) then
begin
processes.Add(string(ProcessE.szExeFile));
while Process32Next(Snap,ProcessE) do
processes.Add(string(ProcessE.szExeFile));
end;
CloseHandle(Snap);
i:=0;
webstartcont:=0;
repeat
if (pos(lowercase(processes[i]),lowercase(programm))<>0) then
begin
inc(webstartcont);
if webstartcont>1 then
begin
i:=processes.Count;
result:=true;
end;
end;
inc(i);
until (i>=processes.Count);
processes.Free;
end;
..........
procedure TMainform.FormShow(Sender: TObject);
begin
if isProgrunning(<YourExe,e.g. myprog.exe>) then
begin
showmessage(<...>);
close;
end else ....
end;