Solved

Detecting open files in Delphi

Posted on 1998-05-14
2
900 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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