5

I need to run myApp.exe that in turn will launch iexplore.exe. What is the most robust, generic way (OS bit version agnostic) to do so?

Can you point me to the right registry key /env var/other mean to do so?

Thanks, Guy

Martijn
  • 13,225
  • 3
  • 48
  • 58
Guy
  • 915
  • 2
  • 14
  • 27
  • 4
    Maybe something like this (opens default browser, not necessarily IE): http://stackoverflow.com/questions/2308439/open-default-browser-as-standard-user-c – Fred Larson Apr 28 '11 at 16:16
  • 1
    Nice idea, but I need only IE to launch – Guy May 01 '11 at 12:36
  • 1
    Depends on what you're doing, of course. But if I were running a Windows system and something opened IE when my default browser were set to something else, I'd be very annoyed. – Fred Larson May 02 '11 at 03:19
  • I get you. But I really need IE to launch and not the default :) – Guy May 02 '11 at 08:08
  • 1
    related: http://stackoverflow.com/questions/4212002/how-to-find-out-from-the-windows-registry-where-ie-is-installed – user123444555621 Aug 22 '14 at 07:01

7 Answers7

3

For newer versions of Internet Explorer you can check the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Capabilities\ApplicationDescription.

That being said, the most backward- and forward-compatible way will be to look in the following paths (in this order):

In Registry: HKEY_CLASSES_ROOT\IE.AssocFile.HTM\shell\open\command %ProgramFiles(x86)%\Internet Explorer\iexplore.exe %ProgramFiles%\Internet Explorer\iexplore.exe

Note that 64-bit Windows versions may have two different versions of IE: 32-bit and 64-bit. At least as things are now (with IE9), you'd usually want to use the 32-bit version, since it's better optimized and has better plugin/ActiveX compatibility.

Boaz Yaniv
  • 6,334
  • 21
  • 30
  • In the registry I found this key: HKEY_CLASSES_ROOT\htmlfile\shell\open\command – Guy May 02 '11 at 08:09
3
#include <stdlib.h>  
int main() {     
    system("iexplore.exe");
    return 0; 
} 

in any version of windows that I have ever tried... if you click run then type iexplore.exe, Internet Explorer will run. This should do the same...

g19fanatic
  • 10,567
  • 6
  • 33
  • 63
  • Unless you have a bogus `iexplore.exe` in the current working directory. That could be the path to a malware exploit. – Mark Ransom Apr 28 '11 at 20:26
  • 1
    Or, someone may have deliberately replaced iexplore.exe by a Firefox, because some stupid developer [thought it would be a good idea to always open IE](https://github.com/JetBrains/intellij-community/blob/cdb9746b87deee36970bd4d200d97443839a5b14/platform/platform-api/src/com/intellij/ide/BrowserUtil.java#L477-479) instead of the default browser. – user123444555621 Aug 22 '14 at 07:16
  • How does it know where to find iexplore.exe? – Kyle Delaney Apr 07 '17 at 19:29
1

Another alternative:

CSettingsStore store(TRUE, TRUE);
if (store.Open(_T("Software\\Clients\\StartMenuInternet\\IEXPLORE.EXE\\shell\\open\\command")))
{
    CString strIEPath = _T("");

    store.Read(_T(""), strIEPath);
    store.Close();

    if(PathFileExists(strIEPath))
    {
        // Do whatever
    }
}

You can also change the key to:

store.Open(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE")
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
1

Read the standard value of the registry key HKEY_CLASSES_ROOT\CLSID\{0002DF01-0000-0000-C000-000000000046}\LocalServer32

This is the IE COM server registration.

Matthias Alleweldt
  • 2,453
  • 17
  • 16
  • This is wrong. On my Windows 8.1, that key is set to `"%ProgramFiles(x86)%\Internet Explorer\ielowutil.exe" -CLSID:{0002DF01-0000-0000-C000-000000000046}` – c00000fd Feb 08 '16 at 05:00
1

The proper way is to use %PATH%, since that's not subject to preload attacks.

SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
WCHAR buf[MAX_PATH];
SearchPath(NULL, "iexplore.exe", NULL, MAX_PATH, buf, NULL);
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
MSalters
  • 173,980
  • 10
  • 155
  • 350
  • I know it's been answered a long time ago, but how did you make it work? It always seems to return 0 with error code set to `ERROR_FILE_NOT_FOUND` when I test it on Win 7, 8.2, 10. – c00000fd Oct 17 '18 at 04:20
0

You can look at folders of PATH environment variable. Also in folders %SYSTEMDRIVE%\PROGRA~1\INTERN~1 and %SYSTEMDRIVE%\PROGRA~2\INTERN~1.

EDIT:

  • You can have your own env variabale (say IE_HOME). And ask clients of your program to set it equal to path of IE executable and just use value of this environment variable.
Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111
  • You shouldn't need to look at the folders in `%PATH%`. If you're just trying to run it and it IS in the `%PATH%` (which it is by default) then just running `iexplore` without any folder structure will work, that's what `%PATH%` is for, after all. – corsiKa Apr 28 '11 at 16:26
  • Saying to look at path folders I meant exacly this :) (i.e. to just execute). – Mihran Hovsepyan Apr 28 '11 at 16:28
  • The path environment variable doesn't seem to include iexplore's directory. – Kyle Delaney Apr 07 '17 at 19:30
0

Unless I'm mistaken current version of IE are always installed under "Program Files\InternetExplorer"

So,

string strIEPath;

char cDirectory[MAX_PATH];
if(SHGetSpecialFolderPathA(NULL,cDirectory,CSIDL_PROGRAM_FILES,false))          
{
    strIEPath = cDirectory;
    strIEPath.append("\\InternetExplorer\\iexplorer.exe");
}
João Augusto
  • 2,285
  • 24
  • 28