Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get file owner
Message
De
28/09/2010 09:55:39
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01482984
Message ID:
01482992
Vues:
62
>>>Hi All, does anyone know how to get the owner of a file resident on a Windows 2003 server ?
>>>
>>>I've tried using the FileInfo / FileSecurity / IdentityReference classes and invoking the GetOwner() method but it always returns "Builtin\Administrators"
>>
>>Why do you think what it is returning is wrong? I just tested a few of them using those classes and it returned the correct owner. I verified it by going into Explorer, right-clicking on the file and selecting Properties > Security > Advanced > Owner
>>
>>
>>// using System.Security.AccessControl;
>>// using System.Security.Principal;
>>
>>var fileInfo = new FileInfo (@"C:\Windows\System32\capiprovider.dll");
>>var fileAccessControl = fileInfo.GetAccessControl();
>>var identityReference = fileAccessControl.GetOwner(typeof(NTAccount));
>>// Contains file owner
>>// identityReference.Value
>>
>
>Can I ask you about the use of the Var type there? I know that was a new feature in C# 3.0 but thought it was for occasions when the type is unknown at compile time. Given your expertise I am sure there is a good reason.


You got it wrong, Mike. The type HAS TO BE known at compile time. If not, you cannot use var
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform