一、设置环境变量

  • 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!");
  • 相关文章:

    • 2021-08-08
    • 2022-12-23
    • 2022-12-23
    • 2022-12-23
    • 2022-12-23
    • 2022-12-23
    猜你喜欢
    • 2022-12-23
    • 2021-09-07
    • 2022-12-23
    • 2021-10-25
    • 2022-12-23
    • 2021-06-25
    相关资源
    相似解决方案