GetWindowsDirectory() API returns 错误(vba\vb6)
GetWindowsDirectory() API returns wrong (vba\vb6)
在我的 Windows-Terminal 用户上,我试图让两个应用程序指向同一个 Windows 目录,一个写在 VBA VB6 中的一个。
从 VB6 调用 GetWindowsDirectory() API 时 returns 正确的路径
C:\documents and settings\%user%\Windows
从 VBA 宏调用它时,它 returns
C:\Windows
请注意 相同的结果适用于 GetSystemWindowsDirectory()
可能是 VBA 代码不知道它是一个终端站,我调用了 GetSystemMetrics(SM_REMOTESESSION)
API 返回了 1,这意味着它知道它是一个终端站.
VB6 和 VBA
中使用了完全相同的代码
Windows 2003R2,Office 版本是 2010 64 位(当我输入这个的时候,我想知道它是否相关,知道 vb6 是 32 位 ...)
有什么想法吗?
编辑: 正如下面 IInspectable 所解释的,vba 和 vb6 之间的区别是因为 vb6 不像 Office 那样具有终端服务意识。
您观察到的行为已记录在案。请参阅 备注 部分 GetWindowsDirectory:
Terminal Services: If the application is running in a Terminal Services environment, each user has a private Windows directory. There is also a shared Windows directory for the system. If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.
DUMPBIN tool with the /HEADERS 选项可用于验证是否为二进制文件设置了 IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 标志。
dumpbin /HEADERS WINWORD.EXE
产生以下输出(Microsoft Office 2013 32 位):
OPTIONAL HEADER VALUES
10B magic # (PE32)
...
2 subsystem (Windows GUI)
8140 DLL characteristics
Dynamic base
NX compatible
Terminal Server Aware
...
换句话说:Microsoft Office 是终端服务感知的,从 Microsoft Office 中托管的 VBA 脚本调用 GetWindowsDirectory
将 return 共享 Windows系统目录。
如果您使用 DUMPBIN 检查您的 VB6 应用程序,您会发现它不是终端服务感知的,并且调用 GetWindowsDirectory
将 return 私有 Windows 用户目录。
其他资源:
在我的 Windows-Terminal 用户上,我试图让两个应用程序指向同一个 Windows 目录,一个写在 VBA VB6 中的一个。
从 VB6 调用 GetWindowsDirectory() API 时 returns 正确的路径
C:\documents and settings\%user%\Windows
从 VBA 宏调用它时,它 returns
C:\Windows
请注意 相同的结果适用于 GetSystemWindowsDirectory()
可能是 VBA 代码不知道它是一个终端站,我调用了 GetSystemMetrics(SM_REMOTESESSION)
API 返回了 1,这意味着它知道它是一个终端站.
VB6 和 VBA
中使用了完全相同的代码Windows 2003R2,Office 版本是 2010 64 位(当我输入这个的时候,我想知道它是否相关,知道 vb6 是 32 位 ...)
有什么想法吗?
编辑: 正如下面 IInspectable 所解释的,vba 和 vb6 之间的区别是因为 vb6 不像 Office 那样具有终端服务意识。
您观察到的行为已记录在案。请参阅 备注 部分 GetWindowsDirectory:
Terminal Services: If the application is running in a Terminal Services environment, each user has a private Windows directory. There is also a shared Windows directory for the system. If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.
DUMPBIN tool with the /HEADERS 选项可用于验证是否为二进制文件设置了 IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 标志。
dumpbin /HEADERS WINWORD.EXE
产生以下输出(Microsoft Office 2013 32 位):
OPTIONAL HEADER VALUES
10B magic # (PE32)
...
2 subsystem (Windows GUI)
8140 DLL characteristics
Dynamic base
NX compatible
Terminal Server Aware
...
换句话说:Microsoft Office 是终端服务感知的,从 Microsoft Office 中托管的 VBA 脚本调用 GetWindowsDirectory
将 return 共享 Windows系统目录。
如果您使用 DUMPBIN 检查您的 VB6 应用程序,您会发现它不是终端服务感知的,并且调用 GetWindowsDirectory
将 return 私有 Windows 用户目录。
其他资源: