[英]How to change permissions of a folder inside System32 in C#?
我需要以編程方式刪除"NT AUTHORITY\\\\INTERACTIVE"
組在System32目錄內某個目錄上的“創建文件”和“創建目錄”權限。
為此,我編寫了以下代碼:
string windir = Environment.GetEnvironmentVariable("systemroot");
string redirectionFolder = (windir + "\\System32\\Tasks2");
MessageBox.Show(redirectionFolder);
FileSystemAccessRule Tasks = new FileSystemAccessRule("NT AUTHORITY\\INTERACTIVE", FileSystemRights.CreateDirectories | FileSystemRights.CreateFiles, AccessControlType.Deny );
DirectorySecurity dirSecurity = new DirectorySecurity(redirectionFolder, AccessControlSections.Group);
dirSecurity.AddAccessRule(Tasks);
Directory.SetAccessControl(redirectionFolder, dirSecurity);
當我在文件夾C:\\Tasks2
上運行此代碼時,它可以工作。
但是,當我在C:\\Windows\\System32\\Tasks2
上運行它時,我得到了System.IO.DirectoryNotFoundException
異常。 以管理員身份運行該應用程序無濟於事。
為了在C#中更改System32目錄中目錄的權限,我該怎么做?
假設確實存在C:\\Windows\\System32\\Tasks2
,最可能的解釋是您被文件系統重定向器吸引住了。 您有一個32位進程,文件系統重定向器將system32
轉換為SysWOW64
。 因此,盡管您認為自己正在尋找C:\\Windows\\System32\\Tasks2
,但實際上您正在尋找C:\\Windows\\SysWOW64\\Tasks2
。
將您的程序編譯為64位。 或使用C:\\WINDOWS\\SysNative
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.