2015-10-04 80 views
0

我想將可移動驅動器(USB)的權限級別更改爲只讀,並且完全控制當前用戶的窗口。互聯網上有許多教程可用於更改文件,文件夾,目錄,權限級別。但我找不到任何來源來更改USB的權限級別。任何人都可以幫我解決這個問題嗎?我們可以更改驅動器/可移動驅動器權限級別嗎?

我們可以更改或添加新用戶,我們可以通過使用Windows的GUI使用手動方法來更改權限並在Windows中添加新權限。但是我們如何在C#.NET中做到這一點?

+0

爲什麼不能更改根文件夾(例如「G:\」)的權限? –

+0

是的男人我使用根文件夾,謝謝 – Shhzdmrz

回答

0

我只是使用這個Link解決我的問題,包括這個命名空間System.Security.Principal。

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); 
相關問題