Click here to Skip to main content
Licence 
First Posted 25 Mar 2004
Views 28,027
Bookmarked 14 times

Program to list the names of systems connected on a network/workgroup

By | 25 Mar 2004 | Article
Program to list the names of systems connected on a network/workgroup

Introduction

This program acts as a "Network Neighbourhood" which shows all the systems connected to a network of a particular workgroup. You can use this code as a part of a your networking program.

Using the code

Before using this code include Netapi32.lib in Project Settings(Alt+F7)->Links->Object/library modules. Also include the header file "netserv.h" and "netservDlg.h". The main function or class used is NetServerEnum.

#include "netserv.h"
#include "netservDlg.h"

LPSERVER_INFO_101 pBuf = NULL; //allocate buffer
DWORD dwServerType = SV_TYPE_SERVER; // all servers
NET_API_STATUS nStatus;

nStatus = NetServerEnum(NULL,
 dwLevel,
 (LPBYTE *) &pBuf,
 dwPrefMaxLen,
 &dwEntriesRead,
 &dwTotalEntries,
 dwServerType,
 NULL,
 &dwResumeHandle);

If the call succeeds it will return a BOOL value in the form of NET_API_STATUS. All the names would be taken into a buffer and then listed in the list box.

Points of Interest

  1. After NetServerEnum() call, convert pTmpBuf->sv101_name to wchar_t type using swprintf().
        <br>
        wchar_t szWcharBuf[100];
    <br>
        swprintf(szWcharBuf, L"Name: %s\n", pTmpBuf->sv101_name); 
  2. Use this wchar_t buffer in WideCharToMultiByte() API. The second argument should be this flag WC_NO_BEST_FIT_CHARS. That's it; you will get the ANSI string as out parameter.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

sumeet takle

Web Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberMichel Helms16:04 6 Jun '09  
GeneralLies!!! PinmemberAlejandroDG9:02 13 Jul '04  
GeneralRe: Lies!!! Pinmembersumeet takle19:31 1 Feb '10  
GeneralExcuse me, But...... Pinmemberlion3:14 26 Mar '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 26 Mar 2004
Article Copyright 2004 by sumeet takle
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid