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()

你可能感兴趣的:(c 语言 修改 系统环境变量方法)