tags:

views:

34

answers:

3

Hi,

I'm trying to launch a process from my program, namely cmd.exe. Doc says I have to use CreateProcess, and below is how I use it :

CreateProcess((LPCWSTR) "\Windows\cmd.exe", (LPCWSTR) "", 0,0,0,0,0,0,0,0); dw = GetLastError(); printf("%u \n", dw);

The path is the one displayed by the target (on the target, I found a shortcut to cmd.exe which states it resides in \windows.

The error is always the same (2), regardless of how I write the path. Apparently, the error code for (2) is Invalid_Path.

Thanks for having read, GQ

+1  A: 

You are passing an incorrect string to create process. Just casting a byte-oriented string to LPCWSTR doesn't fix the problem that it is incorrect data - you really have to use a Unicode string, which you can spell as

CreateProcess(L"\\Windows\\cmd.exe", NULL, 0,0,0,0,0,0,0,0);

Alternatively, you can use the TEXT() macro.

Martin v. Löwis
Hi,It doesn't seem to make any difference
GQQ
There were more mistakes: you should escape backslashes, and the command line should be writable or NULL. OTOH: are you certain that \windows\cmd.exe actually exists in your CE build?
Martin v. Löwis
The TCHAR macro _T would also work for getting the text to the proper format.
ctacke
A: 

The path is incorrect. Use double backslash.

CreateProcess(TEXT("\\Windows\\cmd.exe"), TEXT(""), 0,0,0,0,0,0,0,0);
gtikok
A: 

Thanks !

It indeed works. I have converted all my char to wchar_t, but I ran in some trouble with the functions.

In the original program, strings were concatenated using strcat. Is wcscat the appropriate replacement ?

gqq