c# - C#:查询远程服务器以查看哪个用户锁定了文件
问题描述
** 编辑:最初的问题不清楚。我无法在任何 .Net 程序集中找到 IADsFileServiceOperations,这就是问题所在 - 并不是我不知道如何使用它**
我已经挖了几个小时了,无法弄清楚...
在 C# 中,有没有办法查询远程文件服务器(最好使用 aManagementObjectSearcher
但不是必要的)并询问它当前哪个用户锁定了文件?
我能想到的最好的方法是
var en = new DirectoryEntry($@"\\{hostName}\root\cimv2");
var fso = sessQuery.NativeObject as IADsFileServiceOperations;
var resources = fso.Resources();
但对于我的生活,我无法弄清楚如何IADsFileServiceOperations
在.Net 项目中使用。
帮助...?请...?
解决方案
IADsFileServiceOperations
是一个公开两个方法的接口:
- IADsFileServiceOperations::资源
- IADsFileServiceOperations::会话
https://docs.microsoft.com/en-us/windows/desktop/api/iads/nn-iads-iadsfileserviceoperations#methods
IADsFileServiceOperations::Resources 方法获取一个指针,该指针指向代表此文件服务上当前打开资源的资源对象集合上的 IADsCollection 接口。
var en = new DirectoryEntry($@"\\{hostName}\root\cimv2");
var fso = sessQuery.NativeObject as IADsFileServiceOperations;
var resources = fso.Resources(); // returns resource objects representing the current open resources on the file
foreach(var res in resources)
{
// res.User
// res.Path
// res.LockCount
if(res.LockCount > 0)
{
// user has lock on file
}
}
更新1:
要将活动目录类型添加到.NET
项目中,您需要向项目添加 COM 引用。转到添加参考对话框,然后按COM
标签并添加Active DS Type Library
。
通过添加此COM
引用,您可以使用所有AD
类型和接口ActiveDS
。
希望它能解决你的问题。
推荐阅读
- python - 从 CSV 列表中选择到表中
- spring-integration - 无法在 Spring Integration Flow 的建议中删除文件资源
- python - 谷歌 colab python3 名称 cv2 未定义
- node.js - 如何在 node-oidc-provider 中重定向失败的登录尝试
- curve-fitting - MATLAB - 指数(exp2)曲线拟合函数在使用原始方程中的拟合值时不给出与绘图相同的输出
- python - 更简单的 python 等价于 R 风格的 grep,包括多个要匹配的东西
- azure - HDInsight 上的 Ambari API 返回 404
- google-sheets - 使用 SUMIF 函数时,有没有办法接受时间戳值(例如 2/12/2019 19:56:16)作为测试标准的范围?
- ruby-on-rails - Rspec - 随机规范通过或失败
- python - Boto3 代码无法通过 sns 服务发送输出