C# 怎样用C#代码实现设置windows环境变量

来源:百度知道 编辑:UC知道 时间:2024/06/02 09:22:23
要求如题。请把具体代码和需要的引用告诉我,通过我的电脑-属性-高级-环境变量 那个我知道,但是不需要。我想要代码实现。先谢谢高手们啦!!

有楼上那么麻烦吗???

这样就够了,
System.Environment.GetEnvironmentVariables();

新建一个window程序,在默认的窗体的load事件里面写上如下代码
Button btn = new Button();
btn.Text = "代码添加的控件"; //设置按钮文字
btn.Location = new Point(50,50); //设置他的坐标
this.Controls.Add(btn); //把btn对象添加到该窗体的控件集合内

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;//注册表操作要引用的空间
using System.Runtime.InteropServices;//调用API函数需要的引用,来加载非托管类user32.dll

namespace 用程序修改环境变量
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
/// <summary>
/// 读取注册表
/// path的路径:[HKEY