Enumerating Windows Network Resources

  • Thread starter Thread starter Rohan Ranade
  • Start date Start date
R

Rohan Ranade

I am trying to implement a crawler in C# that scans all
the shared folders in remote computers in a windows
network. Are there classes in .NET to do this directly?
Please help.

Thank You.
Rohan
 
Rohan,

Your best bet would be to use the classes in the System.Management namespace, as they wrap access to the Windows Management Interface (WMI). This will give you access to most of the information about machines in a consistent, abstract manner. Once you know how to use these classes, you will want to search for instances of the Win32_Share WMI class on the machine to see what is shared.

Hope this helps.
 
Nicholas, Rohan

Just a small remark, like Nicholas has said WMI is the way to go, however there's a little issue which is security related.
Using windows, whenever you want to access remote resources, you need to have access rights to the computers exposing these
resources.
The same applies to WMI, when you need to query remote WMI services, you'll need to have appropriate access rights to do so. Per
default the WMI service is only accessible from the local system, so you will need to give explicit remote access rights for a
specific user on every system you want to query through WMI.

Willy.

Nicholas Paldino said:
Rohan,

Your best bet would be to use the classes in the System.Management namespace, as they wrap access to the Windows Management
Interface (WMI). This will give you access to most of the information about machines in a consistent, abstract manner. Once you
know how to use these classes, you will want to search for instances of the Win32_Share WMI class on the machine to see what is
shared.
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(d0t)paldino=At-exisconsulting'dot|com

I am trying to implement a crawler in C# that scans all
the shared folders in remote computers in a windows
network. Are there classes in .NET to do this directly?
Please help.

Thank You.
Rohan
 
Willy is right, unfortunately. I have exactly this problem.
I need to make a list of shared folders for each particular computer in
a domain. But I have to be logged on as a ordinary user. Then every time
I get "Acces denied".
What other means could I use to make the described list?
(using C# classes, not API) Is it possible through Active directory?

Thx in advance

stej


Nicholas, Rohan

Just a small remark, like Nicholas has said WMI is the way to go,
however there's a little issue which is security related.
Using windows, whenever you want to access remote resources, you need to
have access rights to the computers exposing these
resources.
The same applies to WMI, when you need to query remote WMI services,
you'll need to have appropriate access rights to do so. Per
default the WMI service is only accessible from the local system, so you
will need to give explicit remote access rights for a
specific user on every system you want to query through WMI.

Willy.
 
When running in a Domain, be it an NT or AD you could assign such privilege
to the "Domain users" group.

Willy.
 
Willy, what privilege do you mean?

I'll describe my steps and reasons why I almost gave in.

The first thing I have seen is to set
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa to 0
(the same: in Administrative tools folder go to Local security policy
console
browse to: security settings->local policies->security options ->
doubleclick on Network Access: Sharing and Security Model for local
account
and change it to Classis (from Guest only)

That causes that my connection will not be authenticated as Guest user,
but it will use my account (I hope).

But that didn't work.

Next step: Start --> Run --> wmimgmt.msc
right click WMI control and click Properties.
Click Security tab.
In this window I can set for each namespace a security setting. By
default there are listed two accounts (after click on Security button):
1) Admin - he has full rights for everything
2) Everyone - only limited rights and --And because I (in this case) belong to Everyone group, I cann't connect.

I'm not allowed to set this option to enabled on each particular
computer I need to connect to (and it would be crazy).

That's all I know about the problem so far, so I don't understand what
privileges ("to the Domain users") you are talking about.
 
Next step: Start --> Run --> wmimgmt.msc
*** This is exactly what I'm talking about,
right click WMI control and click Properties.
Click Security tab.
In this window I can set for each namespace a security setting. By
default there are listed two accounts (after click on Security button):
1) Admin - he has full rights for everything
2) Everyone - only limited rights and --
And because I (in this case) belong to Everyone group, I cann't connect.
*** That's a good thing. You don't want everyone to take control over your
PC isn't it?
I'm not allowed to set this option to enabled on each particular
computer I need to connect to (and it would be crazy).

*** You don't have to give everyone remote access, you need to add "domain
users" or "domain accounts" or whatever group /account to the list with
appropriate privileges to the wanted namespace. Say for instance "remote
access" and "partial write" to "domain users", "execute methods", "remote
access" and "full write" to "domain accounts".
If you are not allowed to do this you can't use WMI to control other
machines on the network, point.

Willy.
 
Thx very much, that's what I have been looking for, but haven't been
able to found..

stej
 
Back
Top