c# - 在最终设置中读取属性时出现问题
问题描述
我做了一个程序,它需要一封邮件来开始扫描 PC 中的元素,比如处理器的名称、速度、内存、默认浏览器等。
问题是,在我的本地调试中,程序运行正常,所以我用输出项目制作了一个安装文件,但是,当我运行它时,它给我带来了权限错误,避免这种情况的唯一方法,它正在运行程序作为管理员,但在我所做的其他设置中,永远不要给我那个错误。
这是我的方法:
// Creates the Json to save usermail
public string createMailPropertie(string newEmail)
{
string newRoute = "";
try
{
var jsonObject = new JObject();
jsonObject.Add("userEmail", newEmail);
var json = JsonConvert.SerializeObject(jsonObject);
File.WriteAllText(Directory.GetCurrentDirectory() + @"/userMailPropertie.json", jsonObject.ToString());
// write JSON directly to a file
using (StreamWriter file = File.CreateText(Directory.GetCurrentDirectory() + @"/userMailPropertie.json"))
using (JsonTextWriter writer = new JsonTextWriter(file))
{
jsonObject.WriteTo(writer);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return newRoute;
}
我想知道是否有其他方法可以让它更清洁、更实用。
解决方案
推荐阅读
- android - iOS设备ios麦克风的权限访问
- database - 如何在 oracle 数据库表中插入 csv 或 .txt 文件的日期列?
- java - 开放世界游戏状态保存安卓
- python - Python 多处理性能不佳
- apache-spark - 从 Spark DataFrame 中删除空白值并合并为单行
- python-3.x - 每次我创建一个新的 virtualenv - 我都必须更新 Pip
- android - 将 compilesdkversion 更新为 27 后未调用 Recyclerview 适配器方法
- sql - 在 SQL 中解析 JSON 嵌套数组
- ruby - 使用 Cairo 的 Ruby Gtk3 内存泄漏
- javascript - AJAX 循环结束后执行代码