K
KennethLundin
Hi,
i'm trying to take ownership of a file using C# and .NET 3.5... i'm
trying doing it like this:
FileSecurity fs = new FileSecurity( "filename", AccessControl.Owner);
fs.SetOwner( new System.Security.Principal.NTAccount
( Environent.UserDomainName, Environment.Username));
File.SetAccessControl( "filename", fs);
But it throws already on new FileSecurity: Attempted to perform an
unauthorized operation.
And this might not be wrong, since when I look at the file in explorer
and try to view it's permissions and owner, I can't do that
(permissions listbox are blank and owner field says "Unable to display
current owner"). BUT in explorer, I can take ownership of the file and
then see it's permissions etc.
So I've also tried in my C# program to do something like:
FileSecurity fs = new FileSecurity();
fs.SetOwner( new System.Security.Principal.NTAccount
( Environent.UserDomainName, Environment.Username));
File.SetAccessControl( fs);
Instead of trying to read the existing FileSecurity, just create a new
one and mash it onto the file. But that does not work either, then
SetAccessControl throws with same exception as above...
Conlusion: I do have the rights to take ownership of the file since I
can do it in explorer, but how do I do that programatically in C# ???
//Kenneth
i'm trying to take ownership of a file using C# and .NET 3.5... i'm
trying doing it like this:
FileSecurity fs = new FileSecurity( "filename", AccessControl.Owner);
fs.SetOwner( new System.Security.Principal.NTAccount
( Environent.UserDomainName, Environment.Username));
File.SetAccessControl( "filename", fs);
But it throws already on new FileSecurity: Attempted to perform an
unauthorized operation.
And this might not be wrong, since when I look at the file in explorer
and try to view it's permissions and owner, I can't do that
(permissions listbox are blank and owner field says "Unable to display
current owner"). BUT in explorer, I can take ownership of the file and
then see it's permissions etc.
So I've also tried in my C# program to do something like:
FileSecurity fs = new FileSecurity();
fs.SetOwner( new System.Security.Principal.NTAccount
( Environent.UserDomainName, Environment.Username));
File.SetAccessControl( fs);
Instead of trying to read the existing FileSecurity, just create a new
one and mash it onto the file. But that does not work either, then
SetAccessControl throws with same exception as above...
Conlusion: I do have the rights to take ownership of the file since I
can do it in explorer, but how do I do that programatically in C# ???
//Kenneth