可以把程序本身读到一个字符串中,然后在其末尾添加一个计数的标记来记录。
下面只是一个简单的事例,研究修改一下就可以实现你的要求了
procedure GetExeString(var Str: string);
var
FStream: TFileStream;
begin
FStream := TFileStream.Create(Str, fmOpenRead or fmShareDenyNone);
try
SetLength(Str, FStream.Size);
FStream.Position := 0;
FStream.ReadBuffer(Pointer(Str)^, FStream.Size);
finally
FStream.Free;
end;
end;
function AddRunTagToExe(Str, RTag: string): boolean;
var
ExeString, Str1: string;
MS: TMemoryStream;
i: integer;
begin
Result := False;
ExeString := Str;
GetExeString(ExeString);
Str1 := GetEofTag(ExeString);
if Str1 <> RTag then
begin
for i := Length(RTag) to 50 do
RTag := RTag + ' ';
ExeString := ExeString + RTag;
MS := TMemoryStream.Create;
try
ReNameFile(Str, Str + '.bak');
MS.WriteBuffer(Pointer(ExeString)^, Length(ExeString));
MS.SaveToFile(Str);
DeleteFile(Str + '.bak');
Sleep(500);
finally
MS.Free;
end;
Result := True;
end;
end;