Solved

Detecting open files in Delphi

Posted on 1998-05-14
2
894 Views
Last Modified: 2010-05-18
Is there a way to detect if a file of any kind (for example .mp3-files) is opened? I want to know if a mp3-file is being played on the computer where my app is installed.
0
Comment
Question by:johnrt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Socrates050697 earned 100 total points
ID: 1345748
The only way I know to do this is to try opening the file with exclusive access. If the file is already open then it fails. Heres a function to do it -

note: this function will also return false if the file doesn't exist.

function isFileOpen(Filename: string): boolean;
var
  MyOfStruct: TOfStruct;
  FileHandle: integer;
begin
  FileHandle:=OpenFile(Filename,MyOfStruct,OF_SHARE_EXCLUSIVE);
  if FileHandle=HFILE_ERROR then
  begin
    result:=False;
  end
  else
  begin
    result:=True;
    CloseHandle(FileHandle);
  end;
end;

Hope this helps
Socrates
0
 

Author Comment

by:johnrt
ID: 1345749
Thank you. I'll try it...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question