uses ShellApi, Windows, Registry;
....
Function FileExec(
const sDatei, sParam:
String; iShowCmd: Integer = sw_Shownormal): Integer;
type
TWow64DisableWow64FsRedirection =
function(
Var Wow64FsEnableRedirection: LongBool): LongBool;
StdCall;
TWow64EnableWow64FsRedirection =
function(Wow64FsEnableRedirection: LongBool): LongBool;
StdCall;
var
Wow64FsEnableRedirection: LongBool;
Function IsWin64: Boolean;
begin
With TRegistry.Create
do begin
RootKey := HKEY_LOCAL_MACHINE;
Result := KeyExists('
\SOFTWARE\Wow6432Node');
Free;
end;
end;
var
hHandle: THandle;
// Handle zur DLL
Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
Wow64EnableWow64FsRedirection: TWow64EnableWow64FsRedirection;
begin
if isWin64
then begin // Win64
hHandle := LoadLibrary(PChar('
kernel32.dll'));
if hHandle <> 0
then begin
@Wow64EnableWow64FsRedirection := GetProcAddress(hHandle, '
Wow64EnableWow64FsRedirection');
@Wow64DisableWow64FsRedirection := GetProcAddress(hHandle, '
Wow64DisableWow64FsRedirection');
if (@Wow64EnableWow64FsRedirection <>
nil)
AND (@Wow64DisableWow64FsRedirection <>
nil)
then begin // Alles OK? Dann Datei ausführen!
Wow64DisableWow64FsRedirection(Wow64FsEnableRedirection);
Result := ShellExecute(0,
nil, PChar(sdatei), Pchar(sParam),
nil, iShowCmd);
Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection);
end;
FreeLibrary(hHandle);
end;
end else begin // Normales Win32
Result := ShellExecute(0,
nil, PChar(sdatei), Pchar(sParam),
nil, iShowCmd);
end;
end;