I have a Delphi app that regularly writes to a local disk file. Occasionally it is unable to access the file - a sharing violation results when it tries to open it. A retr
Using NtQuerySystemInformation you can list all opened handles by all the processes then you can use this function to get the file name
function NtQueryInformationFile(FileHandle: THandle;IoStatusBlock: PIO_STATUS_BLOCK; FileInformation: Pointer;Length: DWORD; FileInformationClass: DWORD): NTSTATUS;stdcall; external 'ntdll.dll';
function GetFileNameFromHandle(const hFile: THandle): string;
var
IO_STATUSBLOCK:IO_STATUS_BLOCK;
FileNameInfo:FILE_NAME_INFORMATION;
szFile:String;
begin
FillChar(FileNameInfo.FileName,SizeOf(FileNameInfo.FileName),0);
NtQueryInformationFile(hFile,@IO_STATUSBLOCK,@FileNameInfo,500,9);
szFile:=WideCharToString(FileNameInfo.fileName);
CloseHandle(hFile);
Result:=szFile;
end;
If this is your file than raise up a message ...