在C:\驱动器权限问题中写入文件 [英] Write file in C:\ drive permission issue
问题描述
我用c#开发了一个win应用程序,该应用程序在c:\驱动器的文件夹中生成文件.当尝试生成文件时,会出现权限问题,但是当应用程序在C:\以外的其他驱动器中生成文件时,则不会发生问题.因此,当我将我的应用程序设置分发给最终用户时,我将不会确保将要安装我的应用程序的用户确实具有在C:\驱动器中生成文件的权限.
i have developed a win application with c# which generate file in a folder in c:\ drive. when try to generate file there then problem occur for permission issue but when the application generate file in other drive than C:\ then no problem occur. so when i will distribute my apps setup to end user then i wont be sure that user who will install my apps does has the permission to generate file in C:\ drive.
所以指导我如何克服这个问题. 我应该在Win OS中使用清单来提升应用程序吗?
so guide me how can i overcome this issue. should i Using Manifests to Elevate an application in win OS?
我有一些文章
http://blogs.msdn.com/b/nikhiln/archive/2007/04/19/embed-a-manifest-to-make-an-application-elevate-in-vista.aspx
http://www.codeproject.com/Articles/105506/Getting-Elevated-Privileges-on-Demand-using-C
http://archive.msdn.microsoft.com/KB981778
等......请以正确的知识指导我.谢谢
etc......please guide me with right knowledge. thanks
推荐答案
您可以使用提升的权限再次启动您的应用程序,并在应用程序开始时进行一些检查以查看是否是这种情况.这是一个示例:(请注意不要陷入应用程序自身启动的无穷循环.)
You can start your application again with elevated permission and have some check at the application's start to see if this is the case. Here's an example: (Be careful not to get into an endless loop of the application starting itself.)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1 && args[1] == "-e") Text = "Elevated";
}
private void button1_Click(object sender, EventArgs e)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Application.ExecutablePath,
Arguments = "-e",
Verb = "runas",//-Admin.
}
};
process.Start();
}
}
但是,我同意将信息存储在"C:"中可能不是一个好主意.您可以尝试在类似Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
.
I agree, though, that storing information in "C:" is probably not a good idea. You can try someplace like: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
.
这篇关于在C:\驱动器权限问题中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!