I\'m trying to find out how to programmatically (I\'m using C#) determine the name (or i.p.) of servers to which my workstation has current maps. In other words, at some po
You could use WMI to enumerate and query mapped drives. The following code enumerates mapped drives, extracts the server name portion, and prints that out.
using System;
using System.Text.RegularExpressions;
using System.Management;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"select * from Win32_MappedLogicalDisk");
foreach (ManagementObject drive in searcher.Get()) {
Console.WriteLine(Regex.Match(
drive["ProviderName"].ToString(),
@"\\\\([^\\]+)").Groups[1]);
}
}
}
}
}
You can find the documentaiton of the Win32_MappedLogicalDisk class here. An intro for accessing WMI from C# is here.