[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Network Resource Enumeration / WNetGetResourceParent

Posted on 1998-08-19
7
Medium Priority
?
294 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 80 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 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