can record unc connection?

眉间皱痕 提交于 2019-12-01 13:54:41

You might want to use the Audit Object Access.

The steps you have to follow:

  1. Enable the Audit object access in the Local Computer Policy.
  2. Enable auditing for the object you want to follow.
  3. From your application, use the EventLog.EntryWritten Event to detect the file opening event

Here's a simplistic sample usage, but you'll have to dig in the documentation in order to capture and log as you need to:

class Program
{
    public static void Main()
    {

        EventLog myNewLog = new EventLog("Security", ".", "Microsoft Windows security");

        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;

        Console.ReadLine();
    }

    public static async void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
    {
        await Task.Factory.StartNew(() =>
        {
            if (e.Entry.InstanceId == 4656 || e.Entry.InstanceId == 4663)
            {
                Console.WriteLine(e.Entry.Message);
            }
        });
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!