views:

156

answers:

1

Using C++ (VS2008) I need to be able to enumerate all shared folders on the current machine and get or construct the local and remote names.

We've been using NetShareEnum for this fairly successfully, but have hit a problem where we need to run with a user account with low privileges.

To get the local path using NetShareEnum we need to retrieve at least SHARE_INFO_2 structures - but that requires "Administrator, Power User, Print Operator, or Server Operator group membership".

I've been trying to use WNetOpenEnum and WNetEnumResource instead but I don't seem to be getting the local name back for that for shares either. AFAICS it only enumerates the shares from an external perspective.

So I'd either like help on where I'm going wrong with WNetEnumResource, or a suggestion as to another way of doing this. Any suggestions are much appreciated.

A: 

It sounds like you're specifying RESOURCE_GLOBALNET for the scope, but it's hard to tell what's wrong without seeing your code.

It's hard to help without knowing what you tried and what you got back. For example, what local name are you expecting and what is getting returned? Did you try NetShareEnum with SHARE_INFO_503?

Gabe
I tried all combinations of flags for the first parameter to WNetOpenEnum, but only RESOURCE_GLOBALNET seemed to let me enumerate shares at all. If you know different I'd be happy to give it a try. I've just been using the sample code from http://msdn.microsoft.com/en-us/library/aa385341(VS.85).aspx and have hacked it about in a few different ways - none of which have been very productive, so I didn't post the code.
Phil Nash
The sample code you linked to is recursive so it enumerates the whole network. Are you saying that you don't know how to make it not recursive? Just pass in the NETRESOURCE corresponding to the local machine.
Gabe
From what I could see there wasn't a way to get at the NETRESOURCE for the local machine without potentially iterating the whole network to get it - is there a shortcut?
Phil Nash
TBH I didn't spend too much time looking at that as I was more concerned with the fact that the local name was coming back as NULL anyway. Any ideas on that? I can look at the "whole network" part again.
Phil Nash
Ok, I've edited my question to focus on the "local name" part. I'm still not sure how to get to the local machine without having to enumerate through other machines first (although I don't have to enumerate the shares on those machines, of course.
Phil Nash
Sorry, I only just noticed your update about SHARE_INFO_503. That still requires the higher privilege level - and is not available for XP and W2003, which is our requirement.
Phil Nash