Process.Start filename using %temp%

后端 未结 5 1890
孤街浪徒
孤街浪徒 2021-01-20 04:48

For some odd reaseon this code fails:

p.StartInfo.FileName = @\"%temp%\\SSCERuntime_x86-ENU.msi\";

and this code succes:

p.         


        
5条回答
  •  天涯浪人
    2021-01-20 05:37

    You can use the Environment.ExpandEnvironmentVariables to expand environment variables within a string, then pass that to the Process class:

    p.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%temp%\SSCERuntime_x86-ENU.msi");
    

    This has the added benefits of

    1. Working for any environment variable (%APPDATA%, %COMMONPROGRAMFILES%, etc), and
    2. Working anywhere in the string (e.g. "%temp%\%username%\foo.txt")

提交回复
热议问题