In the moment, I got a problem trying to open an URL (like http://example.com/test/customer.html?sessionid=291697) with ShellExecuteEx. My goal is to see it in the registered standard browser (e.g. Firefox, IE, Chrome...)
procedure RunNoWait(AProgram: string; AParameters: string; AWorkingDirectory: string; AUAC: Boolean; AShow: Integer = SW_SHOWNORMAL);
var
sei: TShellExecuteInfoW;
aRes: Boolean;
begin
// Does not work too:
// aRes := ShellExecute(Application.Handle, 'open', PWideChar(AProgram), 0, 0, SW_SHOW);
// if aRes <= 32 then begin
// RaiseLastOSError;
// end;
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := Application.Handle;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
if AUAC then begin
sei.lpVerb := PWideChar('runas');
end
else begin
sei.lpVerb := PWideChar('open');
end;
sei.lpFile := PWideChar(WideString(aProgram));
sei.lpDirectory := PWideChar(WideString(AWorkingDirectory));
sei.lpParameters := PWideChar(WideString(AParameters));
sei.nShow := AShow;
aRes := ShellExecuteExW(@sei);
try
if not aRes then begin
RaiseLastOSError;
end;
finally
CloseHandle(sei.hProcess);
end;
end;
// later, I call this with:
AAddress := 'http://example.com/test/customer.html?sessionid=291697';
RunNoWait(AAddress, '', '', False);
The WinApi returns GetLastError 1155 (ERROR_NO_ASSOCIATION) and FormatError returns 'There is no application associated with the specified file name extension.'.
When I copy the URL into Windows Explorer, the website is opened in Firefox, for example...
Any ideas, why the URL cannot be opened programmatically?
[edit:] Just found out, that it works with standard browser set to Microsoft Edge... But still doesn't work with Firefox, IE and Chrome. And I can easily open the URL with those browsers manually...
[edit:] One more hint: while testing with standard-browser IE, I noticed, that it works, when IE is already open(???)
[edit:] The Problem only exists when starting the app from Delphi-Debugger. Does anybody know why?
After all, I see, that I was looking into the wrong direction:
The problem existed only, when starting the app from Delphi Debugger.
All browsers work, if you start the app without Delphi.
[edit:] Just found out why: Tools->Options->Debugger-Options->Embarcadero-Debugger->'debug in spawned processes' was active. Seems like those browsers do not want to get debugged... (anyway, we have no source for them)