问题
I am trying to create a tools help the users to control the shared folders, anyway i have a problems with the permissions in the share folder i made everything good but when testing the permissions is not executing
This is command to create a share folder exist:
// use CMD to sharing the folder
System.Diagnostics.Process command = new System.Diagnostics.Process();
command.StartInfo.CreateNoWindow = true;
command.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
command.StartInfo.FileName = "cmd.exe";
command.StartInfo.Arguments = "/C net share " + ShareName + "=D:\\FolderName";
command.Start();
command.WaitForExit();
command.Close();
But the problem for this sharing, giving the Everyone permission read the folder, and i don't want this, i don't know how can i solve this
anyway, i use this two methods to give and remove the account permission
Give permission method:
// Add sharing permission method
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
try
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
Remove permission method:
// remove sharing permission method
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
so, when i tested this methods, nothing changes it's just create a share folder
What is the problem ?
来源:https://stackoverflow.com/questions/23780010/sharing-a-folders-permission-in-c-sharp