2009-11-23 153 views
0

我正在VS2008中執行部署項目,並且在安裝流程結束時,我需要爲本地計算機上的每個人都創建一個具有完全控制權限的共享文件夾域。 我成功創建了共享文件夾,但每個人都有讀取權限。 任何幫助如何做到這一點,將不勝感激。使用C#創建可從域訪問的共享文件夾

謝謝 瓦列

回答

0

我假設你正在使用的ManagementClasscreate a shared folder

設置你的ManagementBaseObject應充分控制每個人的訪問場:

ManagementClass mc = new ManagementClass("win32_share"); 
ManagementBaseObject inParams = mc.GetMethodParameters("Create"); 
inParams["Description"] = "Shared Folder"; 
// ... whathever ... 
inParams["Access"] = null; // <-- should give full control access to everyone 

如果以上不工作,你可能會想嘗試像明確以下與SMT設置的安全級別:

public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) 
    { 
     DirectoryInfo dInfo = new DirectoryInfo(FileName); 

     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); 
    } 

如果以上都沒有幫助,那麼我建議你發佈你的代碼。

+0

代碼沒什麼特別的。安裝程序只是在本地機器上創建一個目錄並嘗試共享它。我也試過你的代碼,但仍然無法使用。 The ManagementClass mc = new ManagementClass(「win32_share」); 代碼的確可以通過域共享目錄,但只能通過對每個人的「讀取」訪問。 AddDirectorySecurity 方法什麼也不做。 – Valeriu 2009-11-24 07:52:03

+0

這是因爲安裝程序是否與系統用戶一起運行,並且沒有足夠的權限? – Valeriu 2009-11-24 07:53:42

+1

我也認爲inParams [「Access」] = null;可以訪問Everyone,但是隻讀 – Valeriu 2009-11-24 08:05:43