在另一个过程中检查环境变量? [英] Check for environment variable in another process?
问题描述
在Windows中,是否有一种方法可以检查是否存在另一个进程的环境变量?只是需要检查是否存在,并不一定能获得价值.
In Windows, is there a way to check for the existence of an environment variable for another process? Just need to check existence, not necessarily get value.
我需要通过代码来做到这一点.
I need to do this from code.
推荐答案
如果您知道存储环境的虚拟地址,则可以使用 ReadProcessMemory
来从其他进程中读取环境.但是,要找到虚拟地址,您需要在线程信息块中四处浏览.进程的线程之一.
If you know the virtual address at which the environment is stored, you can use OpenProcess
and ReadProcessMemory
to read the environment out of the other process. However, to find the virtual address, you'll need to poke around in the Thread Information Block of one of the process' threads.
要获取该信息,您需要致电 GetThreadContext()
,然后调用 SuspendThread()
.但是,为了调用它们,您需要一个线程句柄,您可以通过调用TH32CS_SNAPTHREAD标志的="noreferrer"> CreateToolhelp32Snapshot
,以创建该过程的快照, OpenThread
来获取线程的句柄.
To get that, you'll need to call GetThreadContext()
after calling SuspendThread()
. But in order to call those, you need a thread handle, which you can get by calling CreateToolhelp32Snapshot
with the TH32CS_SNAPTHREAD
flag to create a snapshot of the process, Thread32First
to get the thread ID of the first thread in the process, and OpenThread
to get a handle to the thread.
这篇关于在另一个过程中检查环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!