SetEnvironmentVariable对%var%\ target.extension不起作用

时间:2017-12-16 01:56:18

标签: c# environment-variables

string var1 = "drive";
string var2 = "parent";
string var3 = "testpath";
string var4 = "mypath";
string var5 = "partpath";
string var6 = "mypath2";
string path1 = "E:\\";
string path2 = "%drive%ParentFolder";
string path3 = "%parent%\\Parent.txt";
string path4 = "E:\\ParentFolder\\Parent.txt";
string path5 = "E:\\ParentFolder\\";
string path6 = "%partpath%Parent.txt";
Environment.SetEnvironmentVariable(var1, path1, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(var2, path2, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(var3, path3, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(var4, path4, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(var5, path5, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable(var6, path6, EnvironmentVariableTarget.User);

如果我要启动%testpath%(即var3 path3),结果:找不到%parent%Parent.txt

如果我要启动%mypath%(即var4 path4),结果:成功打开Parent.txt

如果我要启动%mypath2%(即var6 path6),结果:找不到%parent%Parent.txt

使用通过SetEnvironmentVariable设置的%var%\ application.exe似乎存在问题。

任何人都有同样的问题吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

如果递归逻辑不起作用,请用getenvironmentalvariable值替换。