Solved

Detecting open files in Delphi

Posted on 1998-05-14
2
883 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
2 Comments
 
LVL 1

Accepted Solution

by:
Socrates050697 earned 100 total points
Comment Utility
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
Comment Utility
Thank you. I'll try it...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now