如何检查是否一个exe从服务器访问 [英] How to check if a exe is accessed from the server

查看:124
本文介绍了如何检查是否一个exe从服务器访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个客户端服务器应用程序。我创建一个更新程序将取代的exe文件,运行脚本,和其他任何需要更新的列表。这将被安装在服务器上。

This is a client server application. I'm creating a update program that will replace a list of exe files, run scripts, and anything else that needs to be updated. This will be installed on the server.

首先,我需要检查可执行文件是通过网络共享打开。我可以通过进入计算机管理,然后共享文件和打开的文件手动完成。这似乎是检查,如果该文件是开放的唯一途径。我尝试使用R / W检查,如果文件被打开但没有奏效。在Win32_ServerConnection看着但这只是列出是开放的而不是名称的文件数。

First I need to check if the executable file is opened via a network share. I can do this manually by going into Computer Management then Shared files and Open files. This seems to be the only way to check if the file is open. I tried using R/W to check if the file is opened but this did not work. Looked at Win32_ServerConnection but this just listed number of files that were open not the names.

我想在Delphi 7编写本,或者如果它不能在Delphi完成C#。我发现,可以查看如何可以做到这一点的服务器,但没有对打开的文件数的程序。

I would like to code this in Delphi 7 or C# if it can't be done in Delphi. I have found a few programs that can view the open files on a server but nothing on how this can be done.

推荐答案

我用这样的功能,检查自己是否可以改变文件系统中的文件。基本上我试图创造了一个名为FNAME新的文件,还是打开现有的(应该有),并得到有效的文件句柄。如果失败,那么该文件正在使用中。
的功能实际上并没有创建一个文件,也不会改变现有的filessytem(我永远不会做与处理任何事情)。它只是检查我是否能得到一个文件句柄到文件,我想用它做什么。

I use a function like this to check whether I can alter a file on the filesystem. Basically I try to "create" a new file called fName, still opening the existing (should it exist) and get a valid file handle to it. If that fails, then the file is in use. The function does NOT actually create a file, nor does it alter the existing filessytem (I never do anything with the handle). It simply check whether I can get a file Handle to the file, should I want to do something with it.

这也适用于文件从份额被打开上。远程计算机

This also works for files being opened from a share on a remote computer.

 function IsFileInUse(fName: string): boolean;
  var
    HFileRes: HFILE;
  begin
    Result := false;
    if not FileExists(fName) then
      exit;
    HFileRes := CreateFile(pchar(fName),
      GENERIC_READ or GENERIC_WRITE,
      0, nil, OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL,
      0);
    Result := (HFileRes = INVALID_HANDLE_VALUE);
    if not Result then
      CloseHandle(HFileRes);
  end;

这篇关于如何检查是否一个exe从服务器访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆