如果我尝试使用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 \源\ ADM ALLUSERSPROFILE:C:\ ProgramData APPDATA:C:\ Users \ bens \ AppData \ Roaming asl.log:Destination = file 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 Files CommonProgramFiles(x86):C:\ Program Files (x86)\ Common Files 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 \ includ 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系列6型号23步进10, GenuineIntel 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 \模块\ PUBLIC:C:\ Users \ Public PVC_DDK_DIR:C:\ WinDDK \ 6000 QTJAVA:C:\ Program 文件(x86)\ Java \ jre6 \ lib \ ext \ QTJava.zip SESSIONNAME:控制台 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 \ T ools \ 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 路径:C:\ Perl的\网站\ 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 Driver Test Manager \ Controller \; C:\ Program Files(x86)\ FogBugz \ FogBugz命令 行客户端; C:\ Program Files(x86)\ Microsoft SQL Server \ 100 \ Tools \ Binn \; C:\ Program Files \ Microsoft SQL Server \ 100 \ Tools \ Binn \; C:\ Program Files \ Microsof t SQL Server \ 100 \ DTS \ Binn \; C:\ Program Files(x86)\ Microsoft SQL Server \ 100 \ Tools \ Binn \ VSShell \ Common7 \ IDE \; C:\ Program Files (x86)\ Microsoft SQL Server \ 100 \ DTS \ B inn \; C:\ Program Files \ TortoiseSVN \ bin; C:\ Program Files \ SlikSvn \ bin \; C:\ cygwinx \ b in; C:\ Program Files \ Microsoft Windows Performance Toolkit \; C:\ Program 文件(x86)\ Common Files \ Teleca Shared; C:\ Program Files (x86)\ QuickTime \ QTSystem \; C:\ Progr am Files (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 \仓;
那么在Wow64上打破了CreateEnvironmentBlock吗?此外,系统环境似乎在HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment
中定义为什么没有相当于这个?
答案 0 :(得分:0)
这是CreateEnvironmentBlock()的一个错误,MS知道这个问题,并承诺在未来的某些版本中修复它。