Hello,
I'm trying to add a DirectorySecurity ACL entry to an existing
directory (based on some code I found in the msdn).
However, this code only works on local machines because I can't specify
a server to resolve the identity, so when I try on a remote machine it
just can't find the user.
Any ideas how the following code can be applied to a remote server?
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
try
{
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(
Account, Rights, ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
catch (IdentityNotMappedException e)
{
// Exception caught when username is invalid.
}
Cheers everyone!