Guy
Guy

Reputation: 945

How can I find programatically where iexplore.exe is?

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

Upvotes: 5

Views: 3935

Answers (7)

MSalters
MSalters

Reputation: 179809

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);

Upvotes: 1

Andrew Truckle
Andrew Truckle

Reputation: 19107

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")

Upvotes: 1

g19fanatic
g19fanatic

Reputation: 10931

#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...

Upvotes: 3

Boaz Yaniv
Boaz Yaniv

Reputation: 6424

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.

Upvotes: 3

Jo&#227;o Augusto
Jo&#227;o Augusto

Reputation: 2305

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");
}

Upvotes: 0

Mihran Hovsepyan
Mihran Hovsepyan

Reputation: 11098

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.

Upvotes: 0

Matthias Alleweldt
Matthias Alleweldt

Reputation: 2453

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.

Upvotes: 1

Related Questions