现在的位置: 首页 > 综合 > 正文

.net 中如何得到文件的大小,以及文件的所有者

2018年04月06日 ⁄ 综合 ⁄ 共 615字 ⁄ 字号 评论关闭

 

// Get the file info
String fileName = @"C:Users ingwangDesktopprocmon.exe";
FileInfo info 
= new FileInfo( fileName );
Console.WriteLine( info.Length );
FileSecurity security 
= info.GetAccessControl( AccessControlActions.View ); 

// Owner SID:
Type owenerType = Type.GetType("System.Security.Principal.SecurityIdentifier");
IdentityReference ownerId 
= info.GetAccessControl().GetOwner(owenerType);
Console.WriteLine(
"File Owner SID is : {0}", ownerId.Value); 

// Account Name:
NTAccount account = ( NTAccount )( ownerId.Translate( Type.GetType( "System.Security.Principal.NTAccount" ) ) );
Console.WriteLine( account.Value );

 

抱歉!评论已关闭.