2013-06-26 34 views
3

SID我開發應該在Windows 8和7每個人的在Windows 8

運行正如我創建在C一個新的文件夾中的應用程序的一部分.NET 3.5的應用程序:\ ProgramData。

創建文件夾後,我設置了以下ACL - 允許所有人讀取和寫入。

var directorySecurity = directoryInfo.GetAccessControl(); 
var worldSecurityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, null);  
directorySecurity.AddAccessRule(new FileSystemAccessRule(worldSecurityIdentifier, FileSystemRights.Read, AccessControlType.Allow)); 
directorySecurity.AddAccessRule(new FileSystemAccessRule(worldSecurityIdentifier, FileSystemRights.Write, AccessControlType.Allow)); 

在Windows 8我遇到以下行爲:如果我將文件複製到該目錄,當我看到在文件屬性中的安全選項卡上,這是我所看到的。

Security tab of a file that was copied into the directory

我不明白這是誰的用戶,它是如何創建的。以及我爲每個人定義的ACL在哪裏?

看來這個未知的SID獲得了我爲每個人設置的ACL。

我懷疑這可能是因爲我正在開發.net 3.5而不是4,但是當我將目標框架更改爲4時,它沒有幫助。

當我檢查在調試什麼worldSecurityIdentifier,這是我得到

enter image description here

誰能幫我想出解決辦法?

+0

看起來像登錄會話SID。 'S-1-1-0'是世界/每個人。 – user7116

+0

我知道。當我調試我的程序時,我可以看到wourldSecurityIdentifier是s-1-1-0。 – user844541

回答

3

嘗試:

directorySecurity.AddAccessRule(
    new FileSystemAccessRule(
     worldSecurityIdentifier, 
     FileSystemRights.Read | FileSystemRights.Write, 
     InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, 
     PropagationFlags.None, 
     AccessControlType.Allow)); 

這將設置ACE所以它是由子對象繼承。

+0

謝謝!我工作了。但爲什麼? – user844541

+0

原始代碼中的ACE設置爲InheritanceFlags.None,因此它不會傳遞到目錄中新創建的文件。這設置標誌,以便新的文件和目錄將繼承ACE。 – mjk

+0

明白了:)謝謝! – user844541