Click to See Complete Forum and Search --> : CreateProcess parameters of an exe.


Quell
December 19th, 2004, 11:23 AM
HEy.
i need to run a program with sertain parameters.
So i execute the program using CreateProcess:
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);

I put the parameters into lpCommandLine.
But hte process that i make doesn';t execute them. If i amke a shortcut of the program adn add those parameters there it workes...but if i want to do it from a program....doesn't do it....
here is the code with the parameter pushign and all....
am i missing something?
reateProcess(exename, "-asm primary.exe", 0, 0, FALSE, DEBUG_ONLY_THIS_PROCESS,0, 0, &sInfo, &pInfo);
I knwo that the parameter work, beucase they work when i use a shortcut and add them to teh end.
Any ideas where i screwed up? thx

NoHero
December 19th, 2004, 11:35 AM
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:


So I think its a proper solution to pass following string into lpCommandLine:


TCHAR szStr[1024] = "";
_stprintf(szStr, "\"%s\" -asm primary.exe", exename);


And lpApplicationName is NULL.

Why not using ::ShellExecute?

Andreas Masur
December 20th, 2004, 04:30 AM
CreateProcess(exename, "-asm primary.exe", 0, 0, FALSE, DEBUG_ONLY_THIS_PROCESS,0, 0, &sInfo, &pInfo);

Put a space in front of the first parameter...
CreateProcess(exename, " -asm primary.exe", 0, 0, FALSE, DEBUG_ONLY_THIS_PROCESS,0, 0, &sInfo, &pInfo);