要从 32 位进程访问 64 位系统文件夹,您应该使用特殊的“SysNative”别名而不是直接使用“System32”文件夹:
PChar('C:\Windows\SysNative\msconfig.exe')
如果您需要支持 32 位操作系统版本或 64 位编译,请用于IsWow64Process()
检测您的应用是否在 WOW64 下运行:
{$IFDEF WIN64}
function IsWow64: Boolean;
begin
Result := False;
end;
{$ELSE}
function IsWow64Process(hProcess: THandle; out Wow64Process: BOOL): BOOL; stdcall; external 'kernel32.dll' delayed;
function IsWow64: Boolean;
var
Ret: BOOL;
begin
Result := False;
// XP = v5.1
if (Win32MajorVersion > 5) or
((Win32MajorVersion = 5) and (Win32MinorVersion >= 1)) then
begin
if IsWow64Process(GetCurrentProcess(), Ret) then
Result := Ret <> 0;
end;
end;
{$ENDIF}
var
errorcode: integer;
SysFolder: string;
begin
If IsWow64 then
SysFolder := 'SysNative'
else
SysFolder := 'System32';
errorcode := ShellExecute(0, 'open', PChar('C:\Windows\'+SysFolder'+\msconfig.exe'), nil, nil, SW_NORMAL);
if errorcode <= 32 then
ShowMessage(SysErrorMessage(errorcode));
end;