从C#进程中读取环境变量 [英] Read environment variables from a process in C#

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

问题描述

我想从进程A中的C#代码中读取进程B的环境变量.我已经在C ++中看到了一些解决方案,但是还没有尝试将其适应C#.是否可以从C#中获得,如果没有,是否有人包装了C ++解决方案?

I want to read the environment variables of process B from C# code in process A. I have seen some solutions for this in C++ but haven't tried adapting these to C#. Is this possible from C#, and if not, has anyone wrapped a C++ solution yet?

推荐答案

我浏览了Isalamon和Daniel Hilgarth提供的链接,以及CLR Profiler的 GetServicesEnvironment()方法中的代码,似乎正在做同样的事情,经过一些测试,发现最可靠的解决方案是

I've skimmed through the links provided by Isalamon and Daniel Hilgarth, and also the code in CLR Profiler's GetServicesEnvironment() method which seems to be doing the same thing, and after a bit of testing found that the most reliable solution is Oleksiy's code (pure C# with P/Invoke) which he published in this blog post. It still has the limitation, where you have to be a 64bit process to read the env vars of another 64bit process.

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

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