problem creating a process

I am trying to learn how to create a new process using CreateProcess. I found some code online and it works to start the notepad application:
1
2
3
4
5
6
7
8
9
10
if(CreateProcess("C:\Windows\notepad.exe"
"example.txt", // Additional application arguments
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&siStartupInfo,
&piProcessInfo) == FALSE) 


However when I try to start some other application, like the internet explorer, it doesn't work:

1
2
3
4
5
6
7
8
9
10
11
if(CreateProcess("C:\Program Files\Internet Explorer\iexplore.exe", // Application name
"Home  Partners HealthCare.mht", // Additional application arguments, could be //NULL
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&siStartupInfo1,
&piProcessInfo1) == FALSE)
// Could not start application 


Why is it so?
Thanks
1. You are using ANSI strings. You MUST use CreateProcessA.
2. If CreateProcessA() returns FALSE you can then call GetLastError() and FormatMessage() to find out why it failed.
Thanks webJose. I found that I needed double slashes for it to work:
C:\\Program Files\\Internet Explorer\\iexplore.exe
instead of single slashes
C:\Program Files\Internet Explorer\iexplore.exe

Why is it designed so?
In C++, the backslash is the escape character. It is used to insert non-printable characters in string literals, such as the carriage return or the line feed characters. Therefore, you cannot insert a single backslash into a string literal by simply using a single backslash, ergo the two backslashes that become one.
Always use NULL as first argument and use PathQuoteSpaces() API exported from shlwapi.dll to format second argument of CreateProcess function.
Topic archived. No new replies allowed.