我的程序在运行中,希望能设置临时环境变量。
我知道在CMD下通过执行 set xxxx=something 可以设置一个临时环境变量xxxx。
那么如何在程序运行时设置临时环境变量呢?(不用生成bat文件的方法)谢谢我知道取环境变量是 GetEnvironmentVariable('xxxx'),函数,那么设置有类似的方法吗?

解决方案 »

  1.   

    你能找到GetEnvironmentVariable
    为什么找不到SetEnvironmentVariable呢BOOL SetEnvironmentVariable(    LPCTSTR lpName, // address of environment variable name  
        LPCTSTR lpValue  // address of new value for variable 
       );lpNamePoints to a null-terminated string that specifies the environment variable whose value is being set. The operating system creates the environment variable if it does not exist and lpValue is not NULL. lpValuePoints to a null-terminated string containing the new value of the specified environment variable. If this parameter is NULL, the variable is deleted from the current process's environment.