0
THE SOLUTION (almost)
I always suspected that this would be just a few lines of code..
Here is the guts of it...
1. Add a reference to: System.DirectoryServices.dll
2. Here is the code...
using System.DirectoryServices;
...
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach(System.DirectoryServices.DirectoryEntry dDom in root.Children) {
foreach(System.DirectoryServices.DirectoryEntry dPC in dDom.Children) {
Console.WriteLine( dDom.Name + "/"+dPC.Name);
}
}
This returns for me every computer on the workgroup.
Note that if your machine 'knows' of other workgroups, this app might lock up as it looks for computers on workgroup that you are not connected to.
Therefore, put a condition in so it only does the inner loop for machine names, if the workgroup matches what you are looking for. In this case "MYWORKGROUP";
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach(System.DirectoryServices.DirectoryEntry dDom in root.Children) {
if (dDom.Name == "MYWORKGROUP"){
foreach(System.DirectoryServices.DirectoryEntry dPC in dDom.Children) {
Console.WriteLine( dDom.Name + "/"+dPC.Name);
}
}
}
There might be a better way to stop it locking up on a workgroup that the machine has been on before, but is not connected to now, but I don't know it.
Post it here if you work it out.
Anyway.. This is almost the solution. As you can see, I get the workgroup name, and the machine name.. But no folder name. This might no matter in my case, as I know what folder I am looking for. But it would be good to know if that is possible.

0
Or could it be that the ASP.NET user account does not have permission to return a list of network shares (that point to other machines)?
0
I seemed to have found the allowable PropertyData for this object..
IsArray | Gets or sets a value indicating whether the property is an array. |
IsLocal | Gets or sets a value indicating whether the property has been defined in the current WMI class. |
Name | Gets or sets the name of the property. |
Origin | Gets or sets the name of the WMI class in the hierarchy in which the property was introduced. |
Qualifiers | Gets or sets the set of qualifiers defined on the property. |
Type | Gets or sets the CIM type of the property. |
Value | Gets or sets the current value of the property. |
And none of them return for me the shares I have that to other machines..
I'm still looking for a solution for this
0
I have just found out that the code above, is only returning shares on the local machines. ie: the machine the code is running on..
This machine has many other shared directorys to different machines..
It is them I need a list of.
So instead of this...
\\LocalMachine\Apps
\\LocalMachine\Dev
I need this
\\OtherMachine1\Temp
\\OtherMachine1\Docs
\\AnotherMachine\Images
\\YetAnotherPC\MoreImages
0
Thanks for your reply.. I too looked on Google, but did not find anything as useful as the link you sent.
I have tried it out and it works, mostly..
I have repeated the code here to save others going to that link..
ManagementClass shares = new ManagementClass("Win32_Share" );
try{
ManagementObjectCollection specificShares = exportedShares.GetInstances();
foreach(ManagementObject share in specificShares) {
string sharedFolder = share["Name"];
}
}finally{
shares.dispose();
}
First up, this code has some errors..
The line
ManagementObjectCollection specificShares = exportedShares.GetInstances();
Should be
ManagementObjectCollection specificShares = shares.GetInstances();
Next, this line
string sharedFolder = share["Name"];
should be
string sharedFolder = share["Name"].ToString();
Other than that, make sure you add System.Management to your 'References' and finally, put...
Using System.Management;
At the top of the code.
Now, when I run this code, it returns the shared directory names, perfectly. But it does not return the machine name.. So, instead of getting..
\\Machine1\Apps
.. it gets...
Apps
That line that says 'string sharedFolder = share["Name"]; ' is the key. What other values can I put in share["Name"];?
share["Machine"] maybe... Nope
share["ID"].. nope
There must be a list of these somewhere.
The solution is close.
Thanks again for the link.

0
0
I take it that this is not possible in C# .NET?
Anyone have an idea about this? I am still looking for a solution.
Thanks