Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12433453
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2014-01-18 18:11:31

一、设置环境变量
  1. public void SetPath(string pathValue)
  2.         {
  3.             string pathlist;
  4.             pathlist = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
  5.             string[] list = pathlist.Split(';');
  6.             bool isPathExist = false;

  7.             foreach (string item in list)
  8.             {
  9.                 if (item == pathValue)
  10.                     isPathExist = true;
  11.             }
  12.             if (!isPathExist)
  13.             {
  14.                 Environment.SetEnvironmentVariable("PATH", pathlist + ";" + pathValue, EnvironmentVariableTarget.Machine);
  15.             }
  16.         }

二、程序调用批处理

  1.                 Process proc = new Process();
  2.                 proc.StartInfo.WorkingDirectory = Application.StartupPath;
  3.                 proc.StartInfo.FileName = "service install.bat";
  4.                 proc.StartInfo.Arguments = String.Format("10");
  5.                 proc.StartInfo.CreateNoWindow = true;
  6.                 proc.Start();
  7.                 proc.WaitForExit();
  8.                 MessageBox.Show("Create Success!");

阅读(3912) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~