2015-04-21 39 views
0

我一直在尋找如何以編程方式C:\Program Files由C#加上文件夾的本地服務的特權,並得到了來自該網址http://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net/5398398#5398398如何用C#

他們展示如何爲everyone做到這一點寫上去的文件夾添加本地服務特權用戶。

DirectorySecurity sec = Directory.GetAccessControl(path); 
// Using this instead of the "Everyone" string means we work on non-English systems. 
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); 
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); 
Directory.SetAccessControl(path, sec); 

只是告訴我什麼,我需要上面的代碼,結果local service特權將在一個特定的文件夾中添加改變英寸

我開發了一個windows服務,它將在運行時在其中創建一個文件夾和xml文件。當我從安裝文件安裝我的服務,然後文件夾沒有得到創建,但沒有錯誤也是返回。

所以我調試服務,看到它可以在調試時創建文件夾和XML文件。當我從安裝文件安裝服務時發生問題。我無法捕捉像發生什麼問題一樣的問題。因此,請指導我如何捕獲「爲什麼我的服務無法創建文件夾和文件」等問題以尋找指導。感謝

回答

3
new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null); 

new SecurityIdentifier("S-1-5-19"); 
+0

這是什麼'S-1-5-19' – Mou

+0

[SID結構爲LOCAL SERVICE](的含義https://msdn.microsoft.com/en -us /庫/ cc980032.aspx)。 –