EnvironmentVariableEditor:用C#编辑系统环境变量
来源:互联网 发布:java的封装性例题 编辑:程序博客网 时间:2024/05/23 10:55
下载地址: 【北方网通】 【电信网通】
【下载说明】
1 点击上面的地址,打开下载页面
2 点击"普通下载"--等待30秒--点击"下载"按钮--保存
运行截图:/* * Created by SharpDevelop. * User: Administrator * Date: 2012/10/31 * Time: 11:29 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using System.Collections;using System.IO;namespace EnvironmentVariableEditor{/// <summary>/// Description of MainForm./// </summary>public partial class MainForm : Form{public MainForm(){//// The InitializeComponent() call is required for Windows Forms designer support.//InitializeComponent();//// TODO: Add constructor code after the InitializeComponent() call.//}void ShowException(string msg){MessageBox.Show(msg,"EXCEPTION",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);}void ShowInformation(string msg){this.textBox1.Text += msg + Environment.NewLine;this.textBox1.SelectionStart = this.textBox1.TextLength;this.textBox1.ScrollToCaret();}void MainFormLoad(object sender, EventArgs e){this.checkedListBox1.Items.Clear();this.checkedListBox2.Items.Clear();this.textBox1.Text = "";BtnScanClick(sender,e);}void BtnScanClick(object sender, EventArgs e){try{this.checkedListBox1.Items.Clear();this.checkedListBox2.Items.Clear();// read the environment variable for the userforeach(DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User)){string fmt = "[" + de.Key.ToString() + "]" + de.Value.ToString();this.checkedListBox1.Items.Add(fmt);ShowInformation("Find [" + de.Key.ToString() + "] in User.");}// read the environment variable for the machineforeach(DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine)){string fmt = "[" + de.Key.ToString() + "]" + de.Value.ToString();this.checkedListBox2.Items.Add(fmt);ShowInformation("Find [" + de.Key.ToString() + "] in Machine.");}}catch(Exception ex){ShowException(ex.Message);}}void BtnExportClick(object sender, EventArgs e){try{SaveFileDialog sfd = new SaveFileDialog();sfd.Filter = "EVE File(*.eve)|*.eve";if(sfd.ShowDialog() == DialogResult.OK){if(this.checkedListBox1.SelectedItems.Count > 0){using(StreamWriter sw = new StreamWriter(sfd.FileName,false)){foreach(object o in this.checkedListBox1.CheckedItems){string line = "User\t";string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);string val = fmt.Substring(fmt.IndexOf(']') + 1);line += key + "\t" + val;sw.WriteLine(line);ShowInformation("Write [User][" + key + "] to " + sfd.FileName + ".");}}}if(this.checkedListBox2.SelectedItems.Count > 0){using(StreamWriter sw = new StreamWriter(sfd.FileName,true)){foreach(object o in this.checkedListBox2.CheckedItems){string line = "Machine\t";string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);string val = fmt.Substring(fmt.IndexOf(']') + 1);line += key + "\t" + val;sw.WriteLine(line);ShowInformation("Write [Machine][" + key + "] to " + sfd.FileName + ".");}}}}}catch(Exception ex){ShowException(ex.Message);}}void BtnImportClick(object sender, EventArgs e){try{OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "EVE File(*.eve)|*.eve";if(ofd.ShowDialog() == DialogResult.OK){// read the environment variable editor file typeusing(StreamReader sr = new StreamReader(ofd.FileName)){while(!sr.EndOfStream){string line = sr.ReadLine();string[] parts = line.Split('\t');if(parts.Length == 3){if(parts[0].Equals("User")){Environment.SetEnvironmentVariable(parts[1], parts[2], EnvironmentVariableTarget.User);ShowInformation("Set User Variable [" + parts[1] + "] to " + parts[2] + ".");}if(parts[0].Equals("Machine")){Environment.SetEnvironmentVariable(parts[1], parts[2], EnvironmentVariableTarget.Machine);ShowInformation("Set Machine Variable [" + parts[1] + "] to " + parts[2] + ".");}}}}}}catch(Exception ex){ShowException(ex.Message);}}void BtnEditClick(object sender, EventArgs e){try{if(this.checkedListBox1.CheckedItems.Count > 0){foreach(object o in this.checkedListBox1.CheckedItems){string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);string val = fmt.Substring(fmt.IndexOf(']') + 1);EnvironmentVariableEditor.EditorForm ef = new EditorForm("User", key, val);if( ef.ShowDialog() == DialogResult.OK){if(ef.key != string.Empty && ef.val != string.Empty && ef.target != string.Empty){if(ef.target.Equals("User")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User);ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + ".");}if(ef.target.Equals("Machine")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine);ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + ".");}}}}}if(this.checkedListBox2.CheckedItems.Count > 0){foreach(object o in this.checkedListBox2.CheckedItems){string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);string val = fmt.Substring(fmt.IndexOf(']') + 1);EnvironmentVariableEditor.EditorForm ef = new EditorForm("Machine", key, val);if( ef.ShowDialog() == DialogResult.OK){if(ef.key != string.Empty && ef.val != string.Empty && ef.target != string.Empty){if(ef.target.Equals("User")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User);ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + ".");}if(ef.target.Equals("Machine")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine);ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + ".");}}}}}}catch(Exception ex){ShowException(ex.Message);}}void BtnNewClick(object sender, EventArgs e){try{EnvironmentVariableEditor.EditorForm ef = new EditorForm("New","Key","");if(ef.ShowDialog() == DialogResult.OK){if(ef.target != string.Empty && ef.key != string.Empty && ef.val != string.Empty){if(ef.target.Equals("User")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.User);ShowInformation("Set User Variable [" + ef.key + "] to " + ef.val + ".");}if(ef.target.Equals("Machine")){Environment.SetEnvironmentVariable(ef.key, ef.val, EnvironmentVariableTarget.Machine);ShowInformation("Set Machine Variable [" + ef.key + "] to " + ef.val + ".");}}}}catch(Exception ex){ShowException(ex.Message);}}void BtnDeleteClick(object sender, EventArgs e){try{foreach(object o in this.checkedListBox1.CheckedItems){string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);Environment.SetEnvironmentVariable(key, string.Empty, EnvironmentVariableTarget.User);ShowInformation("Delete User Variable [" + key + " ].");}foreach(object o in this.checkedListBox2.SelectedItems){string fmt = o.ToString();string key = fmt.Substring(fmt.IndexOf('[') + 1,fmt.IndexOf(']') - fmt.IndexOf('[') - 1);Environment.SetEnvironmentVariable(key, string.Empty, EnvironmentVariableTarget.Machine);ShowInformation("Delete Machine Variable [" + key + " ].");}}catch(Exception ex){ShowException(ex.Message);}}}}【更多阅读】
- [译]C# DirectShow编程手册及实例
- [原]Html2Pdf:C调用wkhtmltopdf的API来将Html转换为pdf文件
- [原]C#:SevenZipSharp使用7z.dll来进行压缩与解压缩
- [原]Android NDK开发环境的搭建,无需Cygwin
- [原]C#用firefox3.6下载yunfile的文件
- [译]C#将Enum枚举映射到文本字符串
- [译]TIOBE 2012年10月份编程语言排行榜
- [原]C#实现将文本转换为图片
- [转]开启“以后自动采用相同的动作处理此类文件”命令
- [原]Freeplot: MATLAB来帮你手动画图
- EnvironmentVariableEditor:用C#编辑系统环境变量
- C#访问系统环境变量
- python 获取和编辑windows系统环境变量
- 用emacs编辑c#
- 配置C#的系统环境变量的方法
- C# 实现设置系统环境变量设置
- C#操作注册表,设置系统环境变量
- C# 实现设置系统环境变量设置
- C# 实现设置系统环境变量设置
- 环境变量编辑工具
- linux编辑环境变量
- Linux编辑环境变量
- Windows 系统环境变量(好用)
- 用Delphi修改系统环境变量
- 用Delphi修改系统环境变量
- c# 操作当前应用程序所在路径以及系统环境变量
- 使用C#来清除系统环境变量中无效的路径
- C#读取“我的文档”等特殊系统路径及环境变量
- php基本知识
- 配置android环境
- IOS-objective-c的内存管理
- QA与QC质量管理对比
- next_permutation的使用
- EnvironmentVariableEditor:用C#编辑系统环境变量
- 感悟人生的伤感日志_带着眼泪去流浪
- javasrcipt系列---js闭包
- QT生成在Windows下有图标的exe文件(IDE=QT Creator)
- 主题:我们应当怎样做需求确认:需求规格说明书
- Spring3 MVC 深入研究
- 微信摇一摇传感功能实现
- 使用组态软件开发工程的一般步骤
- 经典的变分法图像去噪的C++实现 TV算法