以编程方式检查计算机管理-共享文件夹-打开文件的文件 [英] programmatically check computer management - shared folders - open files for a file
本文介绍了以编程方式检查计算机管理-共享文件夹-打开文件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一个需要更新的客户端服务器软件.我需要检查当前是否正在访问文件.如果可以的话,这是可能的吗?我可以看到文件是否打开的唯一位置是在共享文件夹中的打开文件下.我已经尝试过此代码,但仅表明该文件未打开.
We have a client server software that needs to be updated. I need to check if the file is currently being accessed. Is this possible if so how Delphi code if possible. The only place I can see if the file is open is under the shared folders open files. I have tried this code but just shows that the file is not opened.
function TfrmMain.FileInUse(FileName: string): Boolean;
var H_File : HFILE;
begin
Result := False;
if not FileExists(FileName) then
begin
showmessage ('Doesnt Exist');
exit;
end;
H_File := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Result := (H_File = INVALID_HANDLE_VALUE);
showmessage('Opened');
if not Result then
CloseHandle(H_File);
end;
推荐答案
我发现 NetFileEnum函数
这篇关于以编程方式检查计算机管理-共享文件夹-打开文件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文