سؤال

I want to use ShellExecute iexplore.exe (with an html file name as a command line arg), even if iexplore isn't associated with html files.

Assuming the user hasn't uninstalled it, how safe is it to do so without supplying a path to the program. This works on my machine, i.e. the default Windows search path contains a path to iexplore.exe. Is it reasonable to expect this on all recent Windows (XP+) machines?

Is there a safer way to ShellExecute iexplore.exe?

(Delphi XE2)

(Although this question stands alone, I'll giving the user the option to run IE in the context of this SO question I asked at the same time: Detect Chrome as browser associated with html files in Windows)

هل كانت مفيدة؟

المحلول

'iexplore.exe' is not in the default search path. It's path is registered in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE key. If this key, for any reason, is missing or pointing to a wrong location, your approach won't work. I would think the probability of this happening would be quite low.

As one alternative, you can use Internet Explorer object. With a broken registry or similar, this may also fail, but it sounds like a more official way to me.

ie := CreateOleObject('InternetExplorer.Application');
ie.Visible := True;
ie.Navigate('http://example.com');

IE Object reference here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top