[英]How Delete A Windows 7 dll File (In System32 Folder) By C# Language
Sometimes I need to delete or replace a dll file in system32 folder of windows 7. 有时我需要删除或替换Windows 7的system32文件夹中的dll文件。
The code below always has Permission Denied Error
: 以下代码始终具有
Permission Denied Error
:
if (File.Exists(@"C:\Windows\system32\mydll.dll"))
{
fileInfo.IsReadOnly = false;
File.Delete(@"C:\Windows\system32\mydll.dll");
}
How can I bypass this error and replace a file in system32 folder? 如何绕过此错误并替换system32文件夹中的文件?
if (File.Exists(@"C:\Windows\System32\mydll.dll"))
{
new Process() { StartInfo = new ProcessStartInfo("cmd.exe", @"/k takeown /f C:\Windows\System32\mydll.dll && icacls C:\Windows\System32\mydll.dll /grant %username%:F") }.Start();
File.Delete(@"C:\Windows\System32\mydll.dll");
}
Note that you can't delete a system DLL like shell32.dll
even after taking ownership but you can rename or move it. 请注意,即使拥有所有权也不能删除像
shell32.dll
这样的系统DLL,但可以重命名或移动它。
A user doesn't have sufficient rights to delete files from c:\\windows\\system32 on Windows Vista and up. 用户没有足够的权限从Windows Vista及更高版本的c:\\ windows \\ system32删除文件。 Even when logged-on using an administrator account.
即使使用管理员帐户登录。 UAC puts a stop to it.
UAC停止了它。 You must ask for elevation to let the user know that you are about to tinker with the private parts.
您必须要求提升高度,以使用户知道您将要修改私有部分。 That requires embedding a manifest in your program to trigger the UAC prompt.
这需要在您的程序中嵌入清单以触发UAC提示。 This answer shows you how.
这个答案告诉你如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.