Add reference to the .net library "System.Managem ent"
Add the using statement:
using System.Manageme nt;
Add this procedure:
private List<string> GetMappedDrives ( string computer )
{
List<string> toReturn = new List<string>();
ConnectionOptio ns options = new ConnectionOptio ns();
options.Imperso nation =
System.Manageme nt.Impersonatio nLevel.Imperson ate;
//Path for the query, specifying which computer to use
ManagementPath basePath = new ManagementPath( @"\\" + computer +
@"\ROOT\CIMV 2" );
//Select all logical drives that are of type 4 which is a
network drive
//Other choices would be:
//0 Unknown
//1 No Root Directory
//2 Removable Disk
//3 Local Disk
//4 Network Drive
//5 Compact Disc
//6 RAM Disk
ObjectQuery query = new ObjectQuery( "SELECT * FROM
Win32_LogicalDi sk WHERE DriveType = 4" );
ManagementScope scope = new ManagementScope ( basePath, options );
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher( scope, query );
//Loop through returned drives
foreach ( ManagementObjec t drive in searcher.Get() )
toReturn.Add( drive.Propertie s["Name"].Value.ToString () );
return toReturn;
}
This connects to WMI on the remote machine and enumerates the mapped drives
on it. You need permission to do this on the machine, so make sure you are
logged onto your machine under an account with admin access to the remote
machine.
Chris Balmer
Network Administrator
Concord International
"lastusernamele ft" wrote:
Is there a .NET method for doing this? I haven't found anything else that
works.
Thanks