strongd
asked on
Scanning Network to get computer names
How do I scan a network to get computer names. Not the users logged on. Just computer names.
use MAPI/ISAPI books.
You can use the "NET VIEW" command, redirect the output to a file, and parse through the file to get a list of names. If I remember right (I don't have Microsoft client installed on my computer at home, so I can't verify these commands right now):
"NET VIEW \\" - list of domains
"NET VIEW /D:domain" - list of computers in a domain
"NET VIEW" - list of computers in your computer's domain
Not the best or most efficient way, but it should work.
"NET VIEW \\" - list of domains
"NET VIEW /D:domain" - list of computers in a domain
"NET VIEW" - list of computers in your computer's domain
Not the best or most efficient way, but it should work.
I had sources to do that, but I dont' find them. Will try to find.
NET VIEW is the MSN / NT approach. Novell networks would require NDIR or some variant.
I know you can map drives for any network (so long as the client conforms to Microsoft's requirements) using the NET command (ie., you can map Banyan drives with "NET USE K: \\StreetTalk\fs_blahblah@b lah@blah") . I'd imagine the VIEW parameter would work as well... I'll try when I go to work and see if it does.
Use the EnumResources library function call
Download the file:
www.frogpond.com/~markg/examples/browse.zip
Implement the 32bit version. It is C code, but you should be able to follow it. Hope this helps.
Regards,
jdyer
Download the file:
www.frogpond.com/~markg/examples/browse.zip
Implement the 32bit version. It is C code, but you should be able to follow it. Hope this helps.
Regards,
jdyer
I have found my project implementing in VB the retrieval of users, computers and user groups through the network.
As it is a zip file, give me your e-mail and I will send it to you or go to my web site, to download it.
waty.thierry@usa.net
http://www.geocities.com/ResearchTriangle/6311/
As it is a zip file, give me your e-mail and I will send it to you or go to my web site, to download it.
waty.thierry@usa.net
http://www.geocities.com/ResearchTriangle/6311/
ASKER
The link is bad. He or she doesn't have a web page anymore.
whose link?? Not mine, I just tried it the day I posted this to make sure!
Regards,
jdyer
Regards,
jdyer
ASKER
This link www.frogpond.com/~markg/examples/browse.zip does not work here. I just tried it again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is heavily commented! Hopefully that will make it easier to understand. I have not actually tested this code (That's my job for tomorrow). I have used similar code, so this SHOULD work. If you would like a copy of my test program then I will send it to you to verify that the code works... HERE IT IS:
// --THIS SHOULD BE DECLARED IN winnetwk.h (but isn't)--
#ifdef __cplusplus
extern "C" {
#endif
DWORD APIENTRY WNetGetResourceParentA(
LPNETRESOURCE lpNetResource,
LPVOID lpBuffer,
LPDWORD lpBufferSize);
DWORD APIENTRY WNetGetResourceParentW(
LPNETRESOURCE lpNetResource,
LPVOID lpBuffer,
LPDWORD lpBufferSize);
#ifdef UNICODE
#define WNetGetResourceParent WNetGetResourceParentW
#else
#define WNetGetResourceParent WNetGetResourceParentA
#endif // !UNICODE
#ifdef __cplusplus
}
#endif
// -------------------------- ---------- ---------- ------
// Takes a listbox as an argument and fills the listbox
// with all of the computers in the network, also sets
// a global static (Label) control to the workgroup name
void CListNetCompsDlg::Enumerat eComputers ( CListBox& lst )
{
LPNETRESOURCE lnpLocalComp;
LPNETRESOURCE lnpWrkGrp;
CString strCompName;
char compName[500];
char workGrp[500];
DWORD compLen;
HANDLE hEnum;
DWORD dwEntries;
DWORD dwResult;
DWORD dwSize;
dwEntries = 0xFFFFFFFF; // enumerate all possible
// entries
dwSize = 16384; // should be plenty of
// room to fill array of
// resources
compLen = sizeof( compName );
// Try to allocate some resources, post a msg on error
lnpLocalComp = (LPNETRESOURCE)GlobalAlloc ( GPTR, sizeof( LPNETRESOURCE ) );
lnpWrkGrp = (LPNETRESOURCE)GlobalAlloc ( GPTR,
sizeof( LPNETRESOURCE ) );
if( (lnpLocalComp == NULL ) || (lnpWrkGrp == NULL ) )
{
MessageBox( "Global Memory Allocation failed!" );
SendMessage( WM_CLOSE );
return;
}
// get the computer name and prepend a "\\" to it
// For example if the computer name is MYPC it will now
// be \\MYPC (this is what a universal network name
// looks like)
GetComputerName( compName, &compLen );
strCompName.Format( "\\\\%s", compName );
// fill the lpRemoteName variable of the NETRESOURCE
// structure with our computer name, we will use it to
// search up in the hierarchy for the workgroup name
lnpLocalComp->lpRemoteName = (char*)
((LPCTSTR)strCompName);
// Do the up-hierarchy search for the workgroup name
compLen = sizeof( LPNETRESOURCE );
dwResult = WNetGetResourceParent( lnpLocalComp,
lnpWrkGrp,
&compLen );
if( dwResult != WN_SUCCESS )
{
MessageBox( "Error getting workgroup!" );
SendMessage( WM_CLOSE );
return;
}
// Remove the leading "\\" for display
strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );
sWorkGroup.SetWindowText( workGrp );
// Delete all current entries in listbox, otherwise
// if this is called onRefresh then it will display
// doubles
lst.ResetContent();
// Try to open a network resource enumeration and post
// a message on error
dwResult = WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
lnpWrkGrp,
&hEnum );
if( dwResult != NO_ERROR )
{
MessageBox( "Could not open network enumeration!" );
SendMessage( WM_CLOSE );
return;
}
GlobalFree( lnpLocalComp );
// make sure dwResult doesn't start out as
// ERROR_NO_MORE_ITEMS
dwResult = ERROR_NO_MORE_ITEMS + 1;
while( dwResult != ERROR_NO_MORE_ITEMS )
{
// Allocate resources
lnpLocalComp = (LPNETRESOURCE)GlobalAlloc ( GPTR,
dwSize );
// Try enumeration, fill list box with returned
// values, show message on error
dwResult = WNetEnumResource( hEnum, &dwEntries,
lnpLocalComp, &dwSize );
if( dwResult == NO_ERROR )
{
CString strTrimmed; // comp names w/o leading
// "\\"
CString strNormal; // CString representation
// of lpRemoteName
for( unsigned int i = 0; i < dwEntries; i++ )
{
strNormal = lnpLocalComp[i].lpRemoteNa me;
// Trim leading "\\" for display
strTrimmed = strNormal.Right(
strNormal.GetLength() - 2 );
lst.AddString( strTrimmed );
}
}
else if( dwResult != ERROR_NO_MORE_ITEMS )
{
MessageBox( "Enumeration Error!" );
SendMessage( WM_CLOSE );
return;
}
}
}
// --THIS SHOULD BE DECLARED IN winnetwk.h (but isn't)--
#ifdef __cplusplus
extern "C" {
#endif
DWORD APIENTRY WNetGetResourceParentA(
LPNETRESOURCE lpNetResource,
LPVOID lpBuffer,
LPDWORD lpBufferSize);
DWORD APIENTRY WNetGetResourceParentW(
LPNETRESOURCE lpNetResource,
LPVOID lpBuffer,
LPDWORD lpBufferSize);
#ifdef UNICODE
#define WNetGetResourceParent WNetGetResourceParentW
#else
#define WNetGetResourceParent WNetGetResourceParentA
#endif // !UNICODE
#ifdef __cplusplus
}
#endif
// --------------------------
// Takes a listbox as an argument and fills the listbox
// with all of the computers in the network, also sets
// a global static (Label) control to the workgroup name
void CListNetCompsDlg::Enumerat
{
LPNETRESOURCE lnpLocalComp;
LPNETRESOURCE lnpWrkGrp;
CString strCompName;
char compName[500];
char workGrp[500];
DWORD compLen;
HANDLE hEnum;
DWORD dwEntries;
DWORD dwResult;
DWORD dwSize;
dwEntries = 0xFFFFFFFF; // enumerate all possible
// entries
dwSize = 16384; // should be plenty of
// room to fill array of
// resources
compLen = sizeof( compName );
// Try to allocate some resources, post a msg on error
lnpLocalComp = (LPNETRESOURCE)GlobalAlloc
lnpWrkGrp = (LPNETRESOURCE)GlobalAlloc
sizeof( LPNETRESOURCE ) );
if( (lnpLocalComp == NULL ) || (lnpWrkGrp == NULL ) )
{
MessageBox( "Global Memory Allocation failed!" );
SendMessage( WM_CLOSE );
return;
}
// get the computer name and prepend a "\\" to it
// For example if the computer name is MYPC it will now
// be \\MYPC (this is what a universal network name
// looks like)
GetComputerName( compName, &compLen );
strCompName.Format( "\\\\%s", compName );
// fill the lpRemoteName variable of the NETRESOURCE
// structure with our computer name, we will use it to
// search up in the hierarchy for the workgroup name
lnpLocalComp->lpRemoteName
((LPCTSTR)strCompName);
// Do the up-hierarchy search for the workgroup name
compLen = sizeof( LPNETRESOURCE );
dwResult = WNetGetResourceParent( lnpLocalComp,
lnpWrkGrp,
&compLen );
if( dwResult != WN_SUCCESS )
{
MessageBox( "Error getting workgroup!" );
SendMessage( WM_CLOSE );
return;
}
// Remove the leading "\\" for display
strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );
sWorkGroup.SetWindowText( workGrp );
// Delete all current entries in listbox, otherwise
// if this is called onRefresh then it will display
// doubles
lst.ResetContent();
// Try to open a network resource enumeration and post
// a message on error
dwResult = WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
lnpWrkGrp,
&hEnum );
if( dwResult != NO_ERROR )
{
MessageBox( "Could not open network enumeration!" );
SendMessage( WM_CLOSE );
return;
}
GlobalFree( lnpLocalComp );
// make sure dwResult doesn't start out as
// ERROR_NO_MORE_ITEMS
dwResult = ERROR_NO_MORE_ITEMS + 1;
while( dwResult != ERROR_NO_MORE_ITEMS )
{
// Allocate resources
lnpLocalComp = (LPNETRESOURCE)GlobalAlloc
dwSize );
// Try enumeration, fill list box with returned
// values, show message on error
dwResult = WNetEnumResource( hEnum, &dwEntries,
lnpLocalComp, &dwSize );
if( dwResult == NO_ERROR )
{
CString strTrimmed; // comp names w/o leading
// "\\"
CString strNormal; // CString representation
// of lpRemoteName
for( unsigned int i = 0; i < dwEntries; i++ )
{
strNormal = lnpLocalComp[i].lpRemoteNa
// Trim leading "\\" for display
strTrimmed = strNormal.Right(
strNormal.GetLength() - 2 );
lst.AddString( strTrimmed );
}
}
else if( dwResult != ERROR_NO_MORE_ITEMS )
{
MessageBox( "Enumeration Error!" );
SendMessage( WM_CLOSE );
return;
}
}
}
ASKER
Thanks for all your help. I will go a head and compile it as a DLL and call it will VB. This will help a whole lot!!!! Thanks again jdyer.
ASKER
Thanks for all your help. I will go a head and compile it as a DLL and call it will VB. This will help a whole lot!!!! Thanks again jdyer.
make sure to #include <winnetwk.h>
I'm not sure what your experience with C++ is...
you'll need to remove the
// Remove the leading "\\" for display
strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );
sWorkGroup.SetWindowText( workGrp );
otherwise the dll call will fail (most probably) since it can't find sWorkGroup. If you need more help, let me know.
Regards,
jdyer
I'm not sure what your experience with C++ is...
you'll need to remove the
// Remove the leading "\\" for display
strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );
sWorkGroup.SetWindowText( workGrp );
otherwise the dll call will fail (most probably) since it can't find sWorkGroup. If you need more help, let me know.
Regards,
jdyer