function ApakahFileSdgDigunakan(FileName: TFileName): Boolean;
var
HFileRes: HFILE;
begin
Result := False;
if not FileExists(FileName) then Exit;
HFileRes := CreateFile(PChar(FileName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
if not Result then
CloseHandle(HFileRes);
end;
// Example
procedure TForm1.Button1Click(Sender: TObject);
begin
if ApakahFileSdgDigunakan('C:\Program Files\Borlandx\Delphi 3\BIN\delphi32.exe') then
ShowMessage('File sedang digunakan')
else
ShowMessage('File Tidak Sedang Digunakan');
end;
0 Response to "Scrip Apakah sebuah File Sedang Digunakan Atau Tidak"
Post a Comment