【发布时间】:2016-02-04 10:22:30
【问题描述】:
我想将一个 xml 文件保存到本地文件系统上的 MyDocuments 文件夹中。为此,我使用以下内容:
xmlDoc.Save(Path.GetPathRoot(savePath + saveName));
savePath 在哪里
String qnPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuesitNote\\");
String savePath = Path.Combine(qnPath, "SavedDecks");
而saveName是用户输入的string,格式为无空格。
由于管理权限问题,我无法执行此操作。到目前为止,我已经尝试了很多解决方案,其中包括:
- Change user type in the manifest file
- Use attributes to try to create an authorization function that saves the file using admin rights
- Create a separate console procedure (a whole other program altogether) that requires admin rights in the manifest file and then tries to save the xml file
第一种方法有效,但我只需要特定方法的管理员权限,即我保存 xml 文件的方法。
第二个给了我System.Security.SecurityException。
第三个似乎可以工作,但实际上并没有创建文件,只是给出了我创建的“成功”消息。 UAC 提示从未出现。
在这一点上,我不知道如何解决这个问题。理想情况下,我只能将管理权限用于一种方法(使用我的第二次尝试),但第三次尝试的修复也会有所帮助。 如何让 UAC 提示出现(第三次尝试),或以其他方式解决我的问题?
【问题讨论】:
标签: c# winforms process console admin