【问题标题】:Why does CreateEnvironmentBlock on a WOW64 process give me PROCESSOR_ARCHITECTURE=AMD64为什么 WOW64 进程上的 CreateEnvironmentBlock 给我 PROCESSOR_ARCHITECTURE=AMD64
【发布时间】:2011-07-19 14:50:34
【问题描述】:

如果我尝试使用 CreateEnvironmentBlock() 从 32 位进程(在 64 位操作系统上)创建环境块,我得到的环境块似乎大部分是正确的,但它与自动创建的环境块有一些不同通过 CreateProcess。最值得注意的是 PROCESSOR_ARCHITECTURE 通常是 32 位进程上的 x86,但来自 CreateEnvironmentBlock 的是 amd64。

BOOL bResult = FALSE;
LPWSTR wszEnvBlock = NULL;
HANDLE tokenHandle;

OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle);

bResult = ::CreateEnvironmentBlock((LPVOID*)&wszEnvBlock, tokenHandle, TRUE);

LPWSTR wszCurrentItem = wszEnvBlock;
LPWSTR wszEqualsSign = NULL;
LPWSTR wszCurrentItemInuse = NULL;

ATL::CStringW wstrCurrentName;
ATL::CStringW wstrCurrentValue;

while (L'\0' != *wszCurrentItem)
{
    // Find the equals and temporarily set it to NULL
    wszCurrentItemInuse = wszCurrentItem;
    wszEqualsSign = wcschr(wszCurrentItem, L'=');
    *wszEqualsSign = L'\0';

    // Copy the Name and then set the equals back as it was
    wstrCurrentName = wszCurrentItem;
    *wszEqualsSign = L'=';

    // Move the current item to the next character after the equals sign,
    // Then copy the Value
    wszCurrentItem = ++wszEqualsSign;
    wstrCurrentValue = wszCurrentItem;

    // Move the current item to the next character after the terminating NULL character.
    wszCurrentItem = wcschr(wszCurrentItem, L'\0');
    wszCurrentItem++;

    // Insert the two read strings into the map
    wprintf(L"%s:%s\n", wstrCurrentName, wstrCurrentValue);
}

bResult = DestroyEnvironmentBlock((LPVOID)wszEnvBlock);

产生以下输出:

ADMSOURCE:\ddwds02\platform8\DesktopPersonalisation\Win7\GO\Source\adm ALLUSERSPROFILE:C:\ProgramData APPDATA:C:\Users\bens\AppData\Roaming asl.log:Destination=文件 AS_WDK6_DIR:C:\WinDDK\6000 AS_WDK7_DIR:C:\WinDDK\7600.16385.0 CLASSPATH:.;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip CommonProgramFiles:C:\Program Files (x86)\Common 文件 CommonProgramFiles(x86):C:\Program Files (x86)\Common 文件 CommonProgramW6432:C:\Program Files\Common Files COMPUTERNAME:APWADEV03 ComSpec:C:\Windows\system32\cmd.exe CYGWIN:nodosfilewarning DEFAULT_CA_NR:CA100 DEVELOPMENT:c:\development DEVLIBS:C:\development\libs FP_NO_HOST_CHECK:NO HOME:c:\users\bens HOMEDRIVE:C: HOMEPATH:\Users\bens INCLUDE:C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\SDK\v1.1\包括 e\ LIB:C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\ LOCALAPPDATA:C:\Users\bens\AppData\Local LOCALHOMESHARE:C:\Users\bens LOGONSERVER:\APWADC01 NUMBER_OF_PROCESSORS:2 操作系统:Windows_NT PATHEXT:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PROCESSOR_ARCHITECTURE:AMD64 PROCESSOR_ARCHITEW6432:AMD64 PROCESSOR_IDENTIFIER:Intel64 Family 6 Model 23 Stepping 10, 正版Intel PROCESSOR_LEVEL:6 PROCESSOR_REVISION:170a ProgramData:C:\ProgramData ProgramFiles:C:\Program Files (x86) ProgramFiles(x86):C:\Program Files (x86) ProgramW6432:C:\Program Files PSModulePath:C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ PUBLIC:C:\Users\Public PVC_DDK_DIR:C:\WinDDK\6000 QTJAVA:C:\Program 文件 (x86)\Java\jre6\lib\ext\QTJava.zip 会话名称:控制台 SP2C_ROOT:C:\Development\SP2C_Win7 SystemDrive:C: SystemRoot:C:\Windows TEMP:C:\Users\bens\AppData\Local\Temp TMP:C:\Users\bens\AppData\Local\Temp USERPROFILE:C:\Users\bens VisualStudioDir:C:\Users\bens\Documents\Visual Studio 2010 VS100COMNTOOLS:C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\VS71COMNTOOLS:C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Common7\Tools\ VS80COMNTOOLS:C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\ VS90COMNTOOLS:c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\windir:C:\Windows WIX:C:\Program Files (x86)\Windows Installer XML v3\ WTTBIN:C:\Program Files\Microsoft 驱动程序测试管理器\控制器\ _NT_SYMBOL_PATH:srv*c:\ websymbols*http://msdl.microsoft.com/download/symbols;sr v*c:\pdbs PATH:C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\Syst em32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GTK 2-Runtime\bin;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\Microsoft 驱动程序测试 Manager\Controller\;C:\Program Files (x86)\FogBugz\FogBugz 命令 Line Client;C:\Program Files (x86)\Microsoft SQL 服务器\100\Tools\Binn\ ;C:\Program Files\Microsoft SQL 服务器\100\Tools\Binn\;C:\Program Files\Microsof t SQL 服务器\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL 服务器\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\B inn\;C:\Program 文件\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin\;C:\cygwinx\b 在;C:\Program Files\Microsoft Windows 性能工具包\;C:\Program 文件 (x86)\Common Files\Teleca Shared;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Progr am 文件 (x86)\AMD\CodeAnalyst\bin;C:\Program Files (x86)\Nmap;c:\Users\bens\scr ipts\win;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;

那么 CreateEnvironmentBlock 刚刚在 wow64 上被破坏了吗?另外,系统环境似乎定义在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

为什么没有类似的 wow64?

【问题讨论】:

  • 嗯,看来我不是第一个看到这个的。也许这是一个错误? eggheadcafe.com/microsoft/Platform-SDK-Shell/32819766/…
  • The bug is at CreateEnviromentBlock, however, the product team currently does not have the plan to fix it in Vista though the fix has been checked into the next version of Windows.... 你在 Win7 上试过了吗?
  • 是的,我在 Win 7 上,错误似乎仍然存在。
  • 您发布的链接中的错误与您在此处报告的不同
  • 不,不完全一样,这是真的。然而,它看起来像 CreateEnvironmentBlock 仍然相当破碎。

标签: windows winapi environment-variables


【解决方案1】:

这是 CreateEnvironmentBlock() 的一个错误,MS 已经意识到这个问题并承诺在未来的某个未指定版本中修复它。

【讨论】:

    猜你喜欢
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2015-07-27
    • 2021-02-25
    相关资源
    最近更新 更多