[英]System.UnauthorizedAccess Exception C#
I currently have a compiled C# program but whenever I run it I get the Windows encountered a problem error. 我目前有一个已编译的C#程序,但是每当我运行它时,我都会遇到Windows错误消息。
This is from a System.UnauthorizedAccess error, how can I give access and remove this error without any need from the user side, since this program is being deployed to a lot of people and I don't want them having to make this fix manually. 这是由于System.UnauthorizedAccess错误造成的,我无需用户端就可以授予访问权限并删除此错误,因为此程序已部署到很多人上,并且我不希望他们必须手动进行此修复。
Thanks 谢谢
You can get the current user's application data folder using the environment variable APPDATA. 您可以使用环境变量APPDATA获取当前用户的应用程序数据文件夹。 Therefore, you can do something like: 因此,您可以执行以下操作:
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
string configFile = Path.Combine(appdata, configFile);
StreamWriter writer = new StreamWriter(configFile);
writer.WriteLine("my config data");
writer.Close();
You can also use this approach to get the temporary folder as well. 您也可以使用这种方法来获取临时文件夹。 You can even generate a random file name using the BCL functions. 您甚至可以使用BCL函数生成随机文件名。 I think it's Path.GetTempFilename()
. 我认为是Path.GetTempFilename()
。
您的应用程序是否随时要求管理员特权?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.