0

I use easy-php devserver 17 on Windows 10 x64 without any problem if I click with the mouse on the "run-devserver.exe" file.

But in my new project, I want to run easy-php from my Delphi program (RAD Studio 10.1 Berlin).

I use this code:

ShellExecute(Handle, 'runas', 'c:\Program Files (x86)\EasyPHP-Devserver-17\run-devserver.exe', nil, nil, SW_SHOWNORMAL);

I get this error (I think it created with MadExcept 3.0):

Aestan Try menu: An error has occurred in Aestan Try Menu.

This error gives me some options, like the bug report, restart the application, close application!

I used some tips in another post like these:

WAMP Server V 2.5 icon is orange,does not respond and no menu

ShellExecute Command doesn't work properly in win10

but they didn't solve my problem.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
siavosh1
  • 41
  • 7
  • I guess you must start as administrator?, the problem is that your application starts without elevated privileges.Does it work when you start your application as administrator (ie right-click, select "run as administrator")? – whosrdaddy Mar 02 '20 at 16:38
  • yes, I start it as administrator but the problem is not solved. – siavosh1 Mar 02 '20 at 17:23
  • Entirely possible that the difference is the working directory. As an aside, never call `ShellExecute` since it can't report errors properly. Use `ShellExecuteEx`. – David Heffernan Mar 03 '20 at 08:29
  • I used "ShellExecuteEx" but the problem not solved. I even used the recommended methods of this link : https://stackoverflow.com/questions/27249995/delphi-7-shellexecute-command-not-working-in-situations – siavosh1 Mar 03 '20 at 11:42
  • Please attention that error is for Dev-server 17, it means that the program is running good and I think "ShellExecute" or "ShellExecuteEx" works without any problem, but maybe I need new configuration to run dev-server with another program or set some permission inside of configuration file, but which file !!? – siavosh1 Mar 03 '20 at 11:55

1 Answers1

0

Problem Solved. when I use this code the Error appears: "The directory name is invalid".

procedure TForm1.Button90Click(Sender: TObject);
var
  FileName, Parameters, Folder: string;
  sei: TShellExecuteInfo;
  Error: DWORD;
  OK: boolean;
begin
   FileName := 'C:\Program Files (x86)\EasyPHP-Devserver-17\run-devserver.exe';
   Parameters := '-lang rus';
   ZeroMemory(@sei, SizeOf(sei));
   sei.cbSize := SizeOf(sei);
   sei.lpFile := PChar(FileName);
   sei.lpParameters := PChar(Parameters);
   sei.lpDirectory := PChar(Folder);
   sei.nShow := SW_SHOWNORMAL;
   OK := ShellExecuteEx(@sei);
   if not OK then
   begin
      Error := GetLastError;
      ShowMessage('Error: ' + IntToStr(Error));
   end;

but when I edit folder and filename string like this code everything is OK.

Folder := 'C:\Program Files (x86)\EasyPHP-Devserver-17\';
FileName := Folder + 'run-devserver.exe';
siavosh1
  • 41
  • 7