use*_*591 3 windows delphi delphi-7 delphi-2010
文件位于C:\ program files(x86)\ my app\myexe.exe中
FileExists('C:\ program files(x86)\ my app\myexe.exe')返回true ;
FileExists('C:\ program files\my app\myexe.exe')返回false ; 在这两种情况下,如果我使用Wow64DisableWow64FsRedirection.
为什么?谢谢
文件系统重定向仅适用于%windir%\system32目录.文件系统重定向器的描述似乎使这一点显而易见.
请注意页面中的注释
应用程序应使用该
SHGetSpecialFolderPath函数来确定%ProgramFiles%目录名称.
编辑结果证明FOLDERID_ProgramFilesx64不适用于在64位窗口上运行的32位应用程序.在这种情况下,您可以使用环境变量%ProgramW6432%.请注意,此变量仅适用于Windows 7及更高版本的32位应用程序.
以下delphi片段允许访问变量:
function GetEnvironmentString(aString : string) : string;
var
dest : string;
retSize : integer;
begin
SetLength(dest, MAX_PATH);
retSize := ExpandEnvironmentStrings(pchar(aString), pchar(dest), MAX_PATH);
if retSize > 0 then
SetLength(dest, retSize - 1);
result := dest;
end;
Run Code Online (Sandbox Code Playgroud)
被称为:
GetEnvironmentString('%ProgramW6432%');
Run Code Online (Sandbox Code Playgroud)
如果您使用的是64位版本的Windows,那么32位应用程序不能用于FOLDERID_ProgramFilesX64显式获取64位的位置Program Files,而是可以使用环境变量扩展.在32位版本的Windows上,此位置无效,并且不会为您提供值.在尝试访问此变量之前,您需要检查系统的位数.
您可以使用函数IsWow64Process来确定这一点.在下面的片段应该让你检查:
function IsWow64: Boolean;
type
TIsWow64Process = function(Handle: Windows.THandle; var Res: Windows.BOOL): Windows.BOOL; stdcall;
var
IsWow64Result: Windows.BOOL;
IsWow64Process: TIsWow64Process;
begin
// Try to load required function from kernel32
IsWow64Process := Windows.GetProcAddress(Windows.GetModuleHandle('kernel32.dll'), 'IsWow64Process');
if Assigned(IsWow64Process) then
begin
// Function is implemented: call it
if not IsWow64Process(Windows.GetCurrentProcess, IsWow64Result) then
raise SysUtils.Exception.Create('IsWow64: bad process handle');
// Return result of function
Result := IsWow64Result;
end
else
// Function not implemented: can't be running on Wow64
Result := False;
end;
Run Code Online (Sandbox Code Playgroud)
总结:FOLDERID_ProgramFiles从32/64位程序访问时给你的32/64位变异,FOLDERID_ProgramFilesX64明确地为您提供了在64位应用程序的64位版本,并且FOLDERID_ProgramFilesX86明确地给你32位的变体.您可以使用环境变量扩展来获取32位应用程序上的64位值
| 归档时间: |
|
| 查看次数: |
2307 次 |
| 最近记录: |