Solved

Network Resource Enumeration / WNetGetResourceParent

Posted on 1998-08-19
7
275 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 121
Looking for a specific application/software 2 104
sum67 challenge 35 93
isEverywhere  challenge 19 72
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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now