Solved

Network Resource Enumeration / WNetGetResourceParent

Posted on 1998-08-19
7
284 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
  • 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 119
if loop in java 3 162
only14 challenge 19 84
tripleUp challenge 7 93
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

749 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