Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateProcess() problem

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Ok, what'm I doing wrong here?
Code:
LPTSTR szCmd;
LPCTSTR szCD;

szCmd = _tcsdup(TEXT("\"C:\\somedir\\someexec.exe\""));
szCD = (LPCTSTR)"\"C:\\somedir\\\";

CreateProcess(Null,
szCmd,
NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL,
szCD,
&si,
&pi);

If I replace szCD with NULL (telling it to use the current processes starting directory) it launches someexec.exe just fine, but that particular exec fails because of the current directory issue.

But if I use it like above it returns error 267: The directory name is invalid.

I'm assuming i'm just casting szCD (have tried with and without the trailing \) wrong or some such, but I'm thoroughly stumped, would appreciate any help.
 
Ok... I've changed szCD to
Code:
LPCWSTR szCD;

szCurrDir = TEXT("C:\\somedir\\\0");
And then it works.

Only problem left is I need long filenames, and quoting it isn't working here

Code:
szCurrDir = TEXT("\"C:\\somedir\\\"\0");
Is a bust.

Any ideas?
 
Have you tried removing the trailing \ from the string?
 
Yes... turns out that for working directories you don't enclose it in quotes.... so
Code:
szCD = TEXT("C:\\Program Files\\E T C\\\0");

Is just fine... it's only when searching for a file that they care because they try to execute a file at every whitespace break... strange but true.

So, problem solved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top