Solved

Network Resource Enumeration / WNetGetResourceParent

Posted on 1998-08-19
7
285 Views
Last Modified: 2013-11-20
I am trying to use WNetGetResourceParent followed by a call to WNetEnumResource to enumerate all of the computers in my workgroup. This is the only feasible way I have found to do it (since starting at the network root and recursively searching down can take years on large networks).

So, when I compiled my code using WNetGetResourceParent, I got an error saying that WNetGetResourceParent could not be found. I linked to mpr.lib, since that is where all of the other WNet* functions are located. Obviously I'm doing something wrong. What is it?

Thx in advance,
  jdyer
0
Comment
Question by:jdyer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 20 total points
ID: 1321019
You are not doing anything wrong. According to the latest Platform SDK documentation, it is declared in winnetwk.h. But it is not. You can't find it in the include files at all. Don't ask me why. Declare it yourself as follows,

DWORD WNetGetResourceParent(
  LPNETRESOURCE lpNetResource,  // Specifies a network resource
                                // for the parent name
  LPVOID lpBuffer,              // Specifies a pointer containing
                                // the parent source
  LPDWORD lpBufferSize,         // Specifies size of location
                                // pointed to by lpbuffer  );

0
 
LVL 1

Author Comment

by:jdyer
ID: 1321020
Um... I am getting a linking error telling me it can't find WNetGetResourceParent. I am linking with mpr.lib (where all the other WNet*) functions are. Any other extra comments to make chensu?

Thx,
  jdyer
0
 
LVL 23

Expert Comment

by:chensu
ID: 1321021
That's because the real names are WNetGetResourceParentA (ANSI version) and WNetGetResourceParentW (Unicode version). A complete declaration is:

#ifdef __cplusplus
extern "C" {
#endif

DWORD APIENTRY WNetGetResourceParentA(
  LPNETRESOURCEA lpNetResource,
  LPVOID lpBuffer,
  LPDWORD lpBufferSize);

DWORD APIENTRY WNetGetResourceParentW(
  LPNETRESOURCEW lpNetResource,
  LPVOID lpBuffer,
  LPDWORD lpBufferSize);

#ifdef UNICODE
#define WNetGetResourceParent  WNetGetResourceParentW
#else
#define WNetGetResourceParent  WNetGetResourceParentA
#endif // !UNICODE

#ifdef __cplusplus
}
#endif

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jdyer
ID: 1321022
I'm giving you the points. Everything compiled fine, thank you very much. I have not actually tryed the code to see if it works, but I trust it will. Thanx again,

Regards,
  jdyer
0
 
LVL 1

Author Comment

by:jdyer
ID: 1321023
Hey chensu, I am encountering a problem... I am sending it a netresource with the lpRemoteName set to \\computerName and the lpProvider and dwType as NULL. It is returning an error every time though. I sent a size of sizeof( LPNETRESOURCE). What am I still doing wrong??? Thanx again for all your help

Regards,
  jdyer
0
 
LVL 23

Expert Comment

by:chensu
ID: 1321024
According to the documentation, lpProvider must not be NULL.

"The lpRemoteName parameter specifies the remote name of the network resource whose parent is required. The lpProvider parameter specifies the network provider that owns the resource. This must be supplied; otherwise, the function could produce incorrect results. The dwType field should be filled in if known; otherwise, it should be set to NULL.

Note that the caller typically knows the values for lpProvider and dwType after previous calls to WNetGetResourceInformation or WNetGetResourceParent. All other parameters in the NETRESOURCE structure are ignored."
0
 
LVL 1

Author Comment

by:jdyer
ID: 1321025
Umm... my documentation says to fill in lpProvider and dwType if known, otherwise supply NULL. I did get it to work, the problem was simple... I was sending in a size of sizeof( LPNETRESOURCE) which is only a pointer (size of 4 bytes) instead of NETRESOURCE (32 bytes). I still had a problem... you actually have to send in about sizeof( NETRESOURCE) * 2 (64 bytes) for it to act well.. I played in safe and sent in 1K. Well, thanx much for your help... would you check out Q.10074590 and see if you can help them out... there are basically two questions being asked... Later...

Regards,
  jdyer
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
Expand macro to ask for filename column 8 40
Best tools for Backup and restore of Wordpress site 6 58
ffmpeg - "rtsp://...... Operation not permitted" 4 92
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question