一、设置环境变量
- 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!");