Checking for connected workstations.

This is a discussion on Checking for connected workstations. within the Windows Programming forums, part of the Platform Specific Boards category; As part of my job I have to copy files onto many machines on my network individually. I would like ...

  1. #1
    Unregistered
    Guest

    Checking for connected workstations.

    As part of my job I have to copy files onto many machines on my network individually. I would like to create a program of my own to copy the files over. I could do the copying of files no problem. What I need to do is figure out how to tell if a machine is switched on or not, when I have a list of machines switched on I could switch on the ones that are off, then allow the program to copy all the necessary files across.

    What is the easiest way using C++ to get a list of all the machines on the network ???


    The machines are all windows 2k and I am using Borland C++ builder 5.

    I don't want administrative tools that can do the job for me I want to create my own tool tailored to my duties. That way I can add all the features I need and not have tons of useless options.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    14

    Angry mmmm!!

    Can anyone help on this the best idea I've ot just now is to check for file existance does anyone have a better idea??.


  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Ok...here's an idea..



    Code:
    #include <windows.h>
    #include <winnetwk.h> //include mpr.lib with project
    #include <iostream>
    using namespace std;
    
    int main (void){
    
    	HANDLE hNetRes;//Handle to resources
    	DWORD dwToEnum = 0xFFFFFFFF,//enumerate all
    		  dwSize = 2048,//size of buffer...make larger if needed
    		  dwErr;
    	LPVOID lpv = NULL;//buffer for info
    	NETRESOURCE *lpnr = NULL;//allow me to address info as NETRESOURCE
    
    	WNetOpenEnum(RESOURCE_CONTEXT,NULL,NULL,
    		NULL,&hNetRes);//Get Handle
    
    	if(!hNetRes){
    		dwErr = GetLastError();
    		cout << "Error " << dwErr << " - ";
    		cout << "Could not begin enum";
    		return 1;
    	}
    	
    	lpv = HeapAlloc(GetProcessHeap(),NULL,dwSize);//Alloc memory
    
    	if(lpv == NULL){
    		dwErr = GetLastError();
    		cout << "Error " << dwErr << " - ";
    		cout << "Could not allocate memory";
    		return 1;
    	}
    
    	lpnr = (NETRESOURCE*)lpv;//sync the pointers...
    	
    	WNetEnumResource(hNetRes,&dwToEnum,lpv,&dwSize);//Get data		
    
    	for(int i = 0;i < dwToEnum;i++,lpnr++){
    		cout << "Found item " << i+1 << " ";
    		if(lpnr->lpRemoteName != NULL)
    			cout << lpnr->lpRemoteName << endl;			
    		else
    			cout << "but no details available" << endl;
    	}
    
    	HeapFree(GetProcessHeap(),NULL,lpv);//Free memory	
    	WNetCloseEnum(hNetRes);	//free handle
    	return 0;
    }
    It has a wierd bug that returns duff info for the first data block enumerated....that's why I added the "but no details available" thing........might just be my crappy home network which is only used for LAN games......or maybe something else.....couldnt be bothered to hunt the error, so I will leave that to you.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    14
    thanks very much that seems like just what I need

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21