首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

c 语言 批改 系统环境变量方法

2012-10-28 
c 语言 修改 系统环境变量方法#includecstdlib#includestringintmain(){using namespace stdstring e

c 语言 修改 系统环境变量方法
#include  <cstdlib>
#include  <string>
 
int  main()
{
    using namespace std;
    
    string envName = ""WHERE_AM_I"";
    string envValue = ""Yeah, I'm here"";
 
    // 设置系统环境变量, 需要管理员权限, 否则拒绝访问
    //string command = "REG ADD "HKLM\\System\\CurrentControlSet\\Control\\Session  Manager\\Environment"";
 
    // 设置当前用户环境变量
    string command = "REG ADD "HKCU\\Environment"";
    command = command + " /v " + envName ;
    command = command + " /d " + envValue;
    
    system (command.c_str());
  
    return 0;
 
}

getenv()
pushenv()

热点排行