Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting a machine on the network, and checking if a file exists

Status
Not open for further replies.

guidoD

Programmer
Dec 2, 2002
4
US
Does anyone know how to check if a machine on the network is on or off in C++? (just like performing the DOS command: C:\>PING machineName)

Also, what is the most efficient way to find out if a file exists at a certain pathname?

Any help is greatly appreciated.
 
I think fopen("\\\\machineName\\someShares\\...", ...) should work fine.
 
Thanks, but won't fopen(\\\\device\\...) open the file if it's there? I just want to check for it's existence.
 
I don't know about Computer on network But to find a file or path use _access(); for syntax Please see MSDN Help
 
Ping? Try using the system() command - whatever parameters you stick in there are executed just like a dos command:

[tt]#include <process.h>

void main( void )
{
system(&quot;ping microsoft.com&quot;);
}
[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
I tried the system(dos_command), but it returns 0 if the command ran successful. So if I ping a machine using this command, it is always going to return 0 whether the machine &quot;replied&quot; or &quot;request timed out&quot;.
 
i forgot to mention - the output is sent to STDOUT which is the equivalent of writing the output to the console. All you need to do is is check the output in STDOUT
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
thanks qednik, but what exactly is STDOUT? a string? a file? how do I check it's contents?
 
system(&quot;ping microsoft.com > outfile.lst&quot;);
after that analyse contents of file outfile.lst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top