使用C#从Windows \ System32目录中删除文件 [英] Delete File from Windows\System32 directory using C#

查看:210
本文介绍了使用C#从Windows \ System32目录中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个C#应用程序,将需要删除一对情侣在System32下的文件,和我做了以下内容:

I'm developing a C# application that will need to delete a couple of files in System32, and I'm doing the following:

File.Delete(@"c:\windows\system32\<file>");

这是行不通的,它不会抛出异常,但它也不会删除该文件。我想这是涉及到权限,但我不知道如何解决它。你能帮忙吗?

This isn't working, it doesn't throw an exception but it also doesn't delete the file. I'm thinking it's related to the permissions, but I'm not sure how to fix it. Can you help?

推荐答案

那么,就让我们假设你是不是做一些恶意的;) 总之,还没有尝试过,但模拟将帮助。

Well, let's just assume you are not doing something malicious ;) Anyway, haven't tried it, but Impersonation would help.

谷歌模仿C#,你会看到很多的例子,而邮件的想法很简单:你的code通常是根据用户的priviledges运行。通过模拟,您可以运行您的code(编程方式,用户不需要做任何事情)根据其他用户的priviledges。因此,如果用户直接访问该文件夹没有UAC restirction,那么,从理论上讲,它应该只是运行即可。但同样,我还没有尝试过,所以不要生气,如果它不能正常工作。只是一个想法。

Google impersonation c# and you'll see lots of examples, and the mail idea is simple: your code is normally running under the priviledges of your user. By impersonation, you may run your code (programatically, user doesn't need to do anything) under the priviledges of another user. So if a user has direct access to that folder without the UAC restirction, then, theoretically, it should just run then. But again, I haven't tried it, so don't get mad if it doesn't work. Just an idea.

这篇关于使用C#从Windows \ System32目录中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆