如何从流程中获取系统环境变量 [英] How to get system environment variable from within the process

查看:76
本文介绍了如何从流程中获取系统环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我遇到了一个问题,我需要获取系统中设置的环境变量X的值。这是一个子进程A,由另一个进程B启动,将X重置为某个错误的值,因此当我为X执行GetEnvironMentVariable时,它返回错误的值...我需要在此编写的原始系统环境值系统的注册表。是否有任何API可以作为标准用户完成此操作....我不想启动另一个shell来实现这一目标。你们有类似的东西吗?



谢谢!

Hello,

I am facing a problem where I need to fetch the value of an environment variable X set in the system. This is a child process A which is being launched by another process B that resets X to some wrong value and thus when I do GetEnvironMentVariable for X, it returns me wrong value...I need the origional system environment value that is written in this system's registry. Is there any API to get this done as a standard user....I don't want to launch another shell to achieve this. Do you guys know something like that?

Thanks!

推荐答案

你在谈论 getenv [ ^ ]?它是一个标准的C库API(推荐用于可移植代码)。



Windows也有GetEnvironmentVariable()和你似乎知道的SetEnvironmentVariable()。一旦设置了变量,就会设置它。没有存储在任何地方的缓存或历史记录。
Are you talking about getenv[^] ? It is a standard C library API (recommended for portable code).

Windows also has GetEnvironmentVariable() amd SetEnvironmentVariable() which you seem to know about. Once a variable has been set, it is set. There is no caching or history that is stored anywhere.


这篇关于如何从流程中获取系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆