delphi - 无法让 msconfig.exe 在 system32 文件夹中运行 shellexecute Delphi

标签 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;

有人见过这个并弄清楚如何从 sys32 运行 msconfig.exe 吗?

最佳答案

此行为是由 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.

关于delphi - 无法让 msconfig.exe 在 system32 文件夹中运行 shellexecute Delphi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12849939/

相关文章:

delphi - 避免在Windows Vista对话框中包装复选框标题

windows - 'ping' 不是内部或外部命令可运行程序或批处理文件错误

dll - 如何在Tcl中加载dll?

c - 为什么访问 C :\Windows\System32\. 的 Windows 命令 .. 在 C 程序中不起作用?

delphi - 过滤而不显示过滤器

delphi - 如何根据其父进程创建子进程?

c++ - 缩放后重新定位矩形

c++ - 如何为 Windows 应用程序创建可移动/可调整大小/可配置的工具栏

winapi - WTSRegisterSessionNotification 有时在 XP home 启动时不起作用

winapi - 私有(private)堆或自行管理内存