Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not get msconfig .exe to run in the system32 folder shellexecute Delphi

Im on Win 7 64b. Im trying to run msconfig from my delphi app. The msconfig.exe file is in the system32 folder . I copied the msconfig.exe to the c:\ and it works great. This looks like some kind of permission issue.

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;

Has anyone seen this and figured out how to run the msconfig.exe from the sys32 .

like image 457
grant1842 Avatar asked Dec 07 '25 04:12

grant1842


1 Answers

This behavior is caused by the File System Redirector as workaround you can use the Wow64DisableWow64FsRedirection and Wow64EnableWow64FsRedirection functions.

{$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.
like image 171
RRUZ Avatar answered Dec 08 '25 19:12

RRUZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!