API function to find username of shared files or folders on network in c# or vb.net
With the help of NetFileEnum or Openfiles.exe of system32, we can get the username who has opened the shared files. Is there any API function or any exe files 开发者_Python百科in any programming language like c#, vb.net, visual c++ to find out who is the user to create, rename, or delete shared files or folders on the network?
Try this one out, it will give you access rights information on a file
string fileName = @"C:\Text.txt";
FileSecurity oFSec = File.GetAccessControl(fileName);
AuthorizationRuleCollection oARC = oFSec.GetAccessRules(true, true, typeof(NTAccount));
foreach (FileSystemAccessRule oFSAR in oARC)
{
Console.WriteLine("User : " + oFSAR.IdentityReference.Value);
Console.WriteLine("Access Control Type : " + oFSAR.AccessControlType.ToString());
Console.WriteLine("File System Rights : " + oFSAR.FileSystemRights.ToString());
}
精彩评论