使用C#从Windows \ System32目录中删除文件文件、目录中、Windows

由网友(芋泥啵啵吻)分享简介:我正在开发一个C#应用程序,将需要删除一对情侣在System32下的文件,和我做了以下内容:I'm developing a C# application that will need to delete a couple of files in System32, and I'm doing the followi...

我正在开发一个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:windowssystem32<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.

阅读全文

相关推荐

最新文章