Solved

Network Resource Enumeration / WNetGetResourceParent

Posted on 1998-08-19
7
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:jdyer
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 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

7 Experts available now in Live!

Get 1:1 Help Now