寻找谁修改共享驱动器文件夹文件的用户 [英] Finding the user who modified the shared drive folder files

查看:152
本文介绍了寻找谁修改共享驱动器文件夹文件的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享驱动器是一台服务器上的其他地方。我希望得到一个通知,这使我谁修改了存在于共享驱动器的任何文件的人的用户名。



目前我使用的FileSystemWatcher的获得通知和堆栈溢出问题提供的代码找出用户名(谁)在C#中修改后的文件查找的用户名。



而是我得到它的共享驱动器是目前计算机的名称。我想在用户名谁了的修改文件共享驱动器上。



我的这段代码是:

 私人字符串GetSpecificFileProperties(字符串的文件,则params INT []索引) 
{
字符串文件名= Path.GetFileName(文件);
串FOLDERNAME = Path.GetDirectoryName(文件);
Shell32.Shell壳=新Shell32.Shell();
Shell32.Folder objFolder;
objFolder = shell.NameSpace(文件夹名);
StringBuilder的SB =新的StringBuilder();
的foreach(在objFolder.Items Shell32.FolderItem2项目())
{
如果(文件名== item.Name)
{
的for(int i = 0 ; I< indexes.Length;我++)
{
sb.Append(objFolder.GetDetailsOf(项目,索引[I])+);
}
中断;
}
}
字符串结果= sb.ToString()修剪()。
如果(result.Length == 0)
{
返回的String.Empty;
}
返回result.Substring(0,result.Length - 1);
}




字符串类型= GetSpecificFileProperties(文件路径,2);
串ObjectKind = GetSpecificFileProperties(文件路径,11);
的DateTime CreatedDate = Convert.ToDateTime(GetSpecificFileProperties(文件路径,4));
的DateTime LastModifiedDate = Convert.ToDateTime(GetSpecificFileProperties(文件路径,3));
的DateTime LastAccessDate = Convert.ToDateTime(GetSpecificFileProperties(文件路径,5));
串LastUser = GetSpecificFileProperties(文件路径,10);
字符串计算机名= GetSpecificFileProperties(文件路径,53);
串文件大小= GetSpecificFileProperties(文件路径,1);


解决方案

我已经得到了修复程序是,
检查可以使用.NET的ObjectSecurity类来实现。在这我们可以使用GetOwner。
它获取谁修改了文件的所有者/创建的文件。
这是一段代码,这将有助于:

 字符串所有者= System.IO.File.GetAccessControl(E .FullPath).GetOwner(typeof运算(System.Security.Principal.NTAccount))的ToString()。 
Console.WriteLine(所有者);


I have a shared drive which is elsewhere on a server. I want to get a notification which gives me the user name of the person who has modified any file present in the shared drive.

Currently I am using the FileSystemWatcher to get the notification and the code provided by Stack overflow question "Find out username(who) modified file in C#" to find the user name.

But Instead I get the name of the computer on which the shared drive is at the moment. I want the username who had modified the file on the shared drive.

My piece of code is :

 private string GetSpecificFileProperties(string file, params int[] indexes)
        {
            string fileName = Path.GetFileName(file);
            string folderName = Path.GetDirectoryName(file);
            Shell32.Shell shell = new Shell32.Shell();
            Shell32.Folder objFolder;
            objFolder = shell.NameSpace(folderName);
            StringBuilder sb = new StringBuilder();
            foreach (Shell32.FolderItem2 item in objFolder.Items())
            {
                if (fileName == item.Name)
                {
                    for (int i = 0; i < indexes.Length; i++)
                    {
                        sb.Append(objFolder.GetDetailsOf(item, indexes[i]) + ",");
                    }
                    break;
                }
            }
            string result = sb.ToString().Trim();
            if (result.Length == 0)
            {
                return string.Empty;
            }
            return result.Substring(0, result.Length - 1);
        }




string Type = GetSpecificFileProperties(filePath, 2);
string ObjectKind = GetSpecificFileProperties(filePath, 11);
DateTime CreatedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 4));
DateTime LastModifiedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 3));
DateTime LastAccessDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 5));
string LastUser = GetSpecificFileProperties(filePath, 10);
string ComputerName = GetSpecificFileProperties(filePath, 53);
string FileSize = GetSpecificFileProperties(filePath, 1);

解决方案

I have got the fix to that, It can be achieved using the ObjectSecurity Class of .NET. In that we can use the GetOwner. It fetches the owner of the file who has modified / created a file. This is the piece of code which would help:

string owner = System.IO.File.GetAccessControl(e.FullPath).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();
Console.WriteLine(owner);

这篇关于寻找谁修改共享驱动器文件夹文件的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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