【发布时间】:2014-03-28 02:23:25
【问题描述】:
环境变量用法的新手。
我正在编写项目设置工具,需要跨会话存储一些用户指定的项目目录路径。 有人建议 Get/SetEvironmentVariable。 所以我设置了一个带有文本框的 Windows 窗体来显示路径。 当我加载它使用 GetEvironmentVariable 的表单时,文本框会按预期填充。 但是当我尝试使用 SetEvironmentVariable 更新值时, 文本框是空的,在重新启动之前不显示更新的变量。
private void button1_Click(object sender, EventArgs e)
{
Environment.SetEnvironmentVariable("my_project_dir", "C:\path\to\my\project" , EnvironmentVariableTarget.Machine );
textBox1.Text = Environment.GetEnvironmentVariable("my_project_dir", EnvironmentVariableTarget.Machine);
}
【问题讨论】:
-
根据一位更有经验的工具编码人员的建议,我选择了应用程序设置而不是环境变量。 stackoverflow.com/questions/453161/…