views:

1647

answers:

4

Hi

Can anyone tell me how to create a process in VC++? I need to execute

regasm.exe testdll /tlb:test.tlb /codebase

command in that process.

+4  A: 

You need to read up on CreateProcess() in msdn. There's sample code on that page.

Magnus Skog
+5  A: 

If you just want to execute a synchronous command (run and wait), your best bet is to just use the system() call (see here) to run it. Yes, I know it's a Linux page but C is a standard, no? :-)

For more fine-grained control of what gets run, how it runs (sync/async) and lots more options, CreateProcess() (see here), and its brethren, are probably better, though you'll be tied to the Windows platform (which may not be of immediate concern to you).

paxdiablo
+1  A: 

Use CreateProcess() to spawn the process, check the return value to ensure that it started okay, then either close the handles to the process and the thread or use WaitForSingleObject() to wait until it finishes and then close handles.

sharptooth
+4  A: 
Kirill V. Lyadvinsky
It's Working Fine Rather Than Above.But meanwhile it is asking under which user it has to run ..Can u explain about this prog SHELLEXECUTEINFO shExecInfo;shExecInfo.lpVerb = L"runas";
Cute
I have modified l"run as" to null then works without asking.ok what does this L stand for and how the process created with this??
Cute
L is for Unicode string.
Kirill V. Lyadvinsky
what about complexity in terms of space and time of creating a process in this way?? Any Idea
Cute
ShellExecute a bit slower than CreateProcess. In fact ShellExecure use CreateProcess in the end. If your code timecritical you should use CreateProcess.
Kirill V. Lyadvinsky