Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2018, 09:23 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 285
Default To check if the given file is in use in delphi5

Dear Expert,

I am using the below function to check if the required file is in use in delphi5
application. The code is working in Windows7. However, it is not working in Windows 10 OS. Kindly help.

Code:
function IsFileInUse(fName: string) : boolean;
var
  HFileRes: HFILE;
begin
  Result := False;
  if not FileExists(fName) then begin
    Exit;
  end;

  HFileRes := CreateFile(PChar(fName)
    ,GENERIC_READ or GENERIC_WRITE
    ,0
    ,nil
    ,OPEN_EXISTING
    ,FILE_ATTRIBUTE_NORMAL
    ,0);

  Result := (HFileRes = INVALID_HANDLE_VALUE);

  if not(Result) then begin
    CloseHandle(HFileRes);
  end;
end;
__________________
Rmt
Reply With Quote
  #2  
Old 07-31-2018, 04:18 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 285
Default

Dear Expert,

Please suggest.

Thanks in advance.
__________________
Rmt
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:37 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.