如何以管理员身份在c#中写入文件?
我有一个 C# 程序,它将 xml 文件写入“C:”磁盘。我将我的程序发布为一键包,因为它仅用于测试目的。但问题是一键式软件包没有“以管理员身份运行”选项。那么我该如何解决这个问题呢?有什么想法吗?
I have c# program which writes an xml file to "C:" disk. I published my program as one click package because it's for test purpose only. But the problem is the one click package doesn't have "run as admin" option. So how can I solve this problem ? Any idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的解决方案是不强制管理员提升绕过内置操作系统安全性。
正确的解决方案是修复损坏的程序。即使只是测试程序,也应该写得正确。
有关更多详细信息,请参阅此问题及其答案。尽管它处理的是
Program Files
文件夹而不是根目录,但潜在的问题和解决方案是相同的。The correct solution is not to force administrator elevation to bypass the built-in operating system security.
The correct solution is to fix the broken program. Even though it's just a test program, it should be written correctly.
See this SO question and the answers for more details. Even though it deals with the
Program Files
folder instead of the root, the underlying problem and solutions are identical.我不知道这是否适用于一键部署,但您可以尝试在可执行文件中包含清单,以请求应用程序以更高的权限运行。
请参阅创建并嵌入应用程序清单 (UAC)。
I don't know if this works with One Click Deployment, but you could try to include an Manifest with your executable to request that the application is run with higher privileges.
See Create and Embed an Application Manifest (UAC).