无法获取msconfig .exe在system32文件夹中运行shellexecute Delphi

gra*_*842 3 delphi winapi system32

我在Win 7 64b上.我试图从我的delphi应用程序运行msconfig.msconfig.exe文件位于system32文件夹中.我将msconfig.exe复制到c:\并且效果很好.这看起来像某种权限问题.

var
errorcode: integer;
 begin
   errorcode :=
ShellExecute(0, 'open', pchar('C:\Windows\System\msconfig.exe'), nil, nil, SW_NORMAL);
if errorcode <= 32 then
ShowMessage(SysErrorMessage(errorcode));
end;
Run Code Online (Sandbox Code Playgroud)

有谁看过这个,并想出如何从sys32运行msconfig.exe.

RRU*_*RUZ 6

此行为是由File System Redirector您可以使用Wow64DisableWow64FsRedirectionWow64EnableWow64FsRedirection函数的解决方法引起的.

{$APPTYPE CONSOLE}


uses
  ShellAPi,
  SysUtils;

Function Wow64DisableWow64FsRedirection(Var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
  External 'Kernel32.dll' Name 'Wow64DisableWow64FsRedirection';
Function Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
  External 'Kernel32.dll' Name 'Wow64EnableWow64FsRedirection';


Var
  Wow64FsEnableRedirection: LongBool;

begin
  try
   Wow64DisableWow64FsRedirection(Wow64FsEnableRedirection);
   ShellExecute(0, nil, PChar('C:\Windows\System32\msconfig.exe'), nil, nil, 0);
   Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Run Code Online (Sandbox Code Playgroud)

  • 在64位系统上的WOW64下运行时,您应该直接使用特殊的"SysNative"别名而不是"System32"文件夹,而不是禁用FS重定向:`PChar('C:\ Windows\SysNative\msconfig.exe' )`.使用`IsWow64Process()`来检测WOW64. (2认同)