完全重複的設置ACL時:https://stackoverflow.com/posts/2035107未經授權的操作上的遠程文件/目錄
試圖刪除文件,並保存在遠程位置操作。 當作爲一個控制檯應用程序運行時,它工作正常,但是從XP_CMDSHELL(SQL服務器)時調用xp_cmdshell的從
[4804] System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
[4804]在System.Security.AccessControl.Win32.GetSecurityInfo運行時 這裏是失敗的例外(ResourceType資源類型,字符串名稱,SafeHandle句柄,AccessControlSections訪問控制段,RawSecurityDescriptor & resultSd) [4804]在System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType資源類型,布爾isContainer,字符串名稱,SafeHandle句柄,AccessControlSections includeSections,布爾createByName, ExceptionFromErrorCode exceptionFromErrorCode,Object exceptionContext) [4804]在System.Security.AccessControl.FileSystemSecurity..ctor(布爾isContainer,字符串名稱,AccessControlSections包含的部分,布爾isDirectory) [4804] at System.Security.AccessControl.DirectorySecurity..ctor(String name,AccessControlSections includeSections) [4804]在System.IO.DirectoryInfo.GetAccessControl(AccessControlSections includeSections) [4804] at Excel.SetAcl(String filename,String account)in D:\ SAABZX01D \ dev \ libraries \ EXCEL \ Class1.cs:line 228 [4804]在Excel.doKEStats(字符串baanId,字符串FROM日期,字符串TODATE)在d:\ SAABZX01D \ dev的\庫\ EXCEL \的Class1.cs:線87
下面是代碼
public static bool SetAcl(string filename,string account)
{
FileSystemAccessRule rule = new FileSystemAccessRule(account, FileSystemRights.FullControl, AccessControlType.Allow);
string path= System.IO.Directory.GetDirectoryRoot(filename);
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(filename);
bool what = false;
DirectorySecurity security = di.GetAccessControl(AccessControlSections.Access);
security.ModifyAccessRule(AccessControlModification.Add, rule, out what);
di.SetAccessControl(security);
return what;
}