In an application that I currently writing I stumbled at a very annoying problem that i've been trying to solve for hours to no avail.
I create a process using CreateProcess() Win32 API, passing NULL as the first arg, and the 2nd arg is in the form:
TEXT("cmd.exe /c AppName Args..")
That works pretty good, but then i want to find out the name of the exe that was started. The above syntax would make CreateProcess search the path for the app (which may or may not contain file extension), so i want to know which exe got started from that call.
I wrote a function, which looks like:
BOOL getProcName(DWO RD pid, LPTSTR lpName);
and calls CreateToolhelp3 2Snapshot / Process32First / Process32Next. That is.. trying to match the pid to some process's parent pid. However, it always fails.
If i don't try to match the parent's pid, but the current enumerating process, it's ok. But then, i get "cmd.exe" as ExeName.
However, if i do call that function like 4-5 times in a loop, SOMETIMES i get the child process.. that is, the one i'm looking for.
But i believe there's gotta be a better way to do it. Hopefully. It just seems that my process needs to wait for something (i don't know what) and then get the process snapshot (because it's not created immidiately, hence the loops to get the result).
If someone can help me out i'd really appreciate it.
thanks
I create a process using CreateProcess() Win32 API, passing NULL as the first arg, and the 2nd arg is in the form:
TEXT("cmd.exe /c AppName Args..")
That works pretty good, but then i want to find out the name of the exe that was started. The above syntax would make CreateProcess search the path for the app (which may or may not contain file extension), so i want to know which exe got started from that call.
I wrote a function, which looks like:
BOOL getProcName(DWO RD pid, LPTSTR lpName);
and calls CreateToolhelp3 2Snapshot / Process32First / Process32Next. That is.. trying to match the pid to some process's parent pid. However, it always fails.
If i don't try to match the parent's pid, but the current enumerating process, it's ok. But then, i get "cmd.exe" as ExeName.
However, if i do call that function like 4-5 times in a loop, SOMETIMES i get the child process.. that is, the one i'm looking for.
But i believe there's gotta be a better way to do it. Hopefully. It just seems that my process needs to wait for something (i don't know what) and then get the process snapshot (because it's not created immidiately, hence the loops to get the result).
If someone can help me out i'd really appreciate it.
thanks