tags:

views:

149

answers:

4

How can I simulate these calls inside a program? Like say I want to find all the active connections. So I want to use netstat -a How could I use that without having to literally having a window open?

+6  A: 

Use CreateProcess, redirecting the output.

If the calling application is not a windows application there is no issue with a console window (because a console programming will, by default, inheirt its parent console).

If the calling application is a windows application, set the right options passed to CreateProcess to default the console window that will be created to hidden.

Richard
+2  A: 

There is system() library function you can use - I guess Windows has it as well because it is standard C function since C89.

qrdl
A: 

You will have to use the "/B" option of 'start' command.

cmd /C start "Title" /B netstat -i

I'm assuming popping console is your main problem, and you a strategy of collecting the data.

Vardhan Varma
A: 

Never use system() (not professional, crappy)
Use Win32 net apis .
See the source code of netstat.