是否可以使用.Net框架以编程方式记录对Windows共享(SMB共享)的访问? [英] Is it possible to programatically log access to a windows share (SMB share) using the .Net framework?

查看:30
本文介绍了是否可以使用.Net框架以编程方式记录对Windows共享(SMB共享)的访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有可能找出谁从Windows共享中读取了文件(理想情况下使用.NET,但Win32本机可以这样做)?

Just wondering if it is possible to figure out who has read files from a Windows share (using .NET ideally but win32 native will do)?

我想做的是为Windows共享创建类似 awstats 的东西,这样我就可以看到谁正在访问哪些文件以及哪些是最受欢迎的文件.

What I'm try to do is create something like awstats for a windows share so I can see who is accessing what and which are the most popular files.

我对更改不感兴趣-我只想记录访问权限(随时间变化)以及ip/主机名和什么文件.

I'm not interested in changes - I just want to log access (with time) along with ip / hostname and what file.

推荐答案

使用WMI ...可以在示例c#代码段下方使用它来识别当前访问份额的人.

this is possible using WMI... below the sample c# snippet used to identify whose accessing the shares currenlty

using System.Management;
 ManagementObjectSearcher search =
             new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_ConnectionShare"); 
        foreach (ManagementObject MO in search.Get())
        {
            string antecedent = MO["antecedent"].ToString();
            ManagementObject share = new ManagementObject(antecedent);


            string dependent = MO["dependent"].ToString();
            ManagementObject server = new ManagementObject(dependent);


            string userName = server["UserName"].ToString();
            string compname = server["ComputerName"].ToString();
            string sharename = server["ShareName"].ToString();
        }

我不确定WMI的核心文件事件列表器.但是您可以很好地将其集成到NoramlFileSystemWatcher中.如果网络路径中检测到更改,则触发上述代码.

Am not sure about the core file event listners for WMI. But you can nicely integrate this into the NoramlFileSystemWatcher. And trigger the above code if there is a change detected in the network path.

这篇关于是否可以使用.Net框架以编程方式记录对Windows共享(SMB共享)的访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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