生活随笔
收集整理的這篇文章主要介紹了
C#修改系统环境变量,调用批处理bat
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、設置環境變量
public?void?SetPath(string?pathValue)????????{????????????string?pathlist;????????????pathlist?=?Environment.GetEnvironmentVariable("PATH",?EnvironmentVariableTarget.Machine);????????????string[]?list?=?pathlist.Split(';');????????????bool?isPathExist?=?false; ????????????foreach?(string?item?in?list)????????????{????????????????if?(item?==?pathValue)????????????????????isPathExist?=?true;????????????}????????????if?(!isPathExist)????????????{????????????????Environment.SetEnvironmentVariable("PATH",?pathlist?+?";"?+?pathValue,?EnvironmentVariableTarget.Machine);????????????}????????}
二、程序調用批處理
????????????????Process?proc?=?new?Process();????????????????proc.StartInfo.WorkingDirectory?=?Application.StartupPath;????????????????proc.StartInfo.FileName?=?"service install.bat";????????????????proc.StartInfo.Arguments?=?String.Format("10");????????????????proc.StartInfo.CreateNoWindow?=?true;????????????????proc.Start();????????????????proc.WaitForExit();????????????????MessageBox.Show("Create Success!");
轉載于:https://www.cnblogs.com/lsgsanxiao/p/6903955.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生
總結
以上是生活随笔為你收集整理的C#修改系统环境变量,调用批处理bat的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。