Your question, your audience. Choose who sees your identity—and your question—with question security.
// Added to the source of the application
var vFileStream : TFileStream;
begin
try
vFileStream := TFileStream.Create( ExtractFilePath(Application.ExeName) + 'InUse.fil',fmCreate or fmShareExclusive);
except
MessageDlg('Program is already in use.', mtInformation, [mbOK], 0);
Exit;
end;
Application.Initialize;
ETC....
end;
function GetMachineName : string;
var buffer:array[0..20] of char;
size:Dword;
begin
fillchar(buffer,0,sizeof(buffer)); //just for sure
size:=sizeof(buffer); //save buffersize
GetComputerName(buffer,size); //fill buffer, bytes read saved in size
Result := trim(copy(strpas(buffer),1,size)); //convert to pascal style
end
procedure CreateLockRelease
var sl : TStringlist;
begin
sl := TStringList.Create;
sl.add(Net Session \\ + GetMachineName + /DELETE /Y);
sl.SaveToFile(ReleaseApplicationLock.bat); // may need to include the full path
sl.free;
end;
procedure CreateLockRelease ;
var sl : TStringlist;
begin
sl := TStringList.Create;
sl.add('Net Session \\' + GetMachineName +' /DELETE /Y');
sl.SaveToFile('ReleaseApplicationLock.bat'); // may need to include the full path
sl.free;
end;
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.