trying to open Internet Explorer with my program, no success

1
2
3
4
	SECURITY_ATTRIBUTES ProcessSecurity,
						ThreadSecurity;
	STARTUPINFO StartupInfo;
	PROCESS_INFORMATION ProcessInfo;


CreateProcess ( TEXT("iexplore.exe"), NULL, &ProcessSecurity, &ThreadSecurity, TRUE, CREATE_NEW_PROCESS_GROUP, NULL, TEXT ("C:/Program Files (x86)/Internet Explorer/"), &StartupInfo, &ProcessInfo);

This line is obviously wrong lol, but what is wrong with it?

i have tried compiling it and running it. It compiles fine, but when tried to run that line, in the MS visual 2008 debug it says "0xc0000005: access violation" or sthg. Help?

thanks
You are taking shortcuts that you shouldn't. Also, Windows expects backslashes as directory separators. Finally, make sure you are properly initializing your process and thread security structures, and your startup info structure. I'm also not sure you want IE to be inheriting open handles from your process.
1
2
#include <windows.h>
#include <shlobj.h> 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
SECURITY_ATTRIBUTES Security = { sizeof( SECURITY_ATTRIBUTES ), NULL, TRUE };
STARTUPINFO StartupInfo = { sizeof( STARTUPINFO ), 0 };

TCHAR lpDirectory[ MAX_PATH ];
TCHAR lpCommandLine[ MAX_PATH ];

// avoid hard-coding your program files directory name. But here I do as you do.
lstrcpy( lpDirectory, TEXT( "C:\\Program Files (x86)\\Internet Explorer" ) );
lstrcpy( lpCommandLine, lpDirectory );
lstrcat( lpCommandLine, TEXT( "\\iexplore.exe" ) );

if (!CreateProcess(
  NULL,  // it will get the app name from the next argument
  lpCommandLine,
  &Security,
  &Security,
  FALSE,  // IE doesn't need your open handles
  CREATE_NEW_PROCESS_GROUP,
  NULL,  // inherit current environment
  lpCurrentDirectory,
  &StartupInfo,
  &ProcessInfo
  ))
  complain_here();

There are ways to find IE's (or whatever the default browser is) path. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;

#include <windows.h>
#include <shlwapi.h>

#ifdef UNICODE
#define ucout wcout
#else
#define ucout cout
#endif

int main()
  {
  TCHAR path[ MAX_PATH ];
  DWORD size = MAX_PATH;
  AssocQueryString(
    ASSOCF_INIT_DEFAULTTOSTAR,
    ASSOCSTR_EXECUTABLE,
    TEXT( ".htm" ),
    TEXT( "Open" ),
    path,
    &size
    );
  ucout << TEXT( "Your browser's full path is: " ) << path << endl;
  return 0;
  }
(Don't forget to link with shlwapi.)

If you just want to get the user's "Program Files" directory:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

#ifdef UNICODE
#define ucout wcout
#else
#define ucout cout
#endif

#include <windows.h>
#include <shlobj.h>

int main()
  {
  TCHAR path[ MAX_PATH ];
  SHGetFolderPath( NULL, CSIDL_PROGRAM_FILES, NULL, 0, path );
  cout << TEXT( "The \"Program Files\" path is: " ) << path << endl;
  return 0;
  }

Hope this helps.
Thanks so much!!

last question now. i have tried using findfile to search directory but no success. how can i make my program search the path of internet explorer?
Well, what file are you looking for?

Duoas gave you code that would find the path to the user's Program Files directory... what are you trying to find within it? The internet explorer directory?

You could assume it's <program files direcotry>\internet explorer, because unless someone (or something) has changed it, that's what it is. If you can't get into the directory, you could display a prompt asking the user where the iexplore.exe file can be found. If you still can't get in, you could ask again, stating that you were unable to enter the directory. You could also tell the user that if they're sure the directory is correct, then they may not have permission to enter the directory.
Last edited on
for my program i want it to search for the directory of IE and run the .exe

I want my program to search the path of IE because other pc might have a different IE path if the owner altered it.

more advanced to it, i want for my program used in the same pc to save the IE directory, so when my program is run again it would not need to search the system of IE.

How do i go about doing these two things?
The first one... well, the path to internet explorer isn't stored in the registry AFAIK (and at any rate, using the registry should be avoided at all costs), so really, you'll have to try and guess or just ask the user.

As for the second one, well that's easy. Just write a file called "iepath.dat" or something containing the path, e.g. C:\Program Files\Internet Explorer\iexplore.exe. Then, when your program is loaded, the first thing it should do is check if that file exists, and if it does, what it's content is. If the file doesn't exist, then you look for the IE path.
ok thx.

now i just need to learn how to create and load a saved file.

thanks for your help guys.
You are making a mistake.

Users will hate you because your program loads IE instead of their selected browser.

If I set my browser to be Opera, for example, and your program starts IE, I will not use your program any more.

It is that simple.

And it isn't just me.


If you want to start the user's browser for a specific page, then use ShellExecute().
http://www.google.com/search?btnI=1&q=msdn+ShellExecute

If you want to start the browser by itself, use the code I gave you above.

If you must start IE, for some valid reason (and "it only works with IE" is not usually considered a valid reason by web designers), then you can find IE's location in the registry:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE

(Yes, it is OK to do that.)

And, as chrisname suggested, and I gave you code for, you could just find the Program Files directory and append "\\Internet Explorer\\iexplore.exe" to it, as all versions of IE (on Windows) are there (AFAIK).

Good luck!
good point. is there a way to read the OS's default program for internet browser so i can open user's default browser?

also is it possible when i close my program, i can close the browser that my program opened? do i use ExitProcess (xxx) if it is possible?
i just discovered something from virtual key code, by using VK_BROWSER_HOME i can open user's default browser. my way of doing my program is bad programming isnt it?

the second question is still on.

thanks for your help guys
Last edited on
Topic archived. No new replies allowed.