468,535 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,535 developers. It's quick & easy.

List mapped drives on Remote Machine

Is there a .NET method for doing this? I haven't found anything else that
works.

Thanks
Nov 4 '05 #1
2 11359
Add reference to the .net library "System.Management"

Add the using statement:
using System.Management;

Add this procedure:

private List<string> GetMappedDrives( string computer )
{
List<string> toReturn = new List<string>();

ConnectionOptions options = new ConnectionOptions();
options.Impersonation =
System.Management.ImpersonationLevel.Impersonate;

//Path for the query, specifying which computer to use
ManagementPath basePath = new ManagementPath( @"\\" + computer +
@"\ROOT\CIMV2" );

//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_LogicalDisk WHERE DriveType = 4" );

ManagementScope scope = new ManagementScope( basePath, options );
ManagementObjectSearcher searcher = new
ManagementObjectSearcher( scope, query );

//Loop through returned drives
foreach ( ManagementObject drive in searcher.Get() )
toReturn.Add( drive.Properties["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

"lastusernameleft" wrote:
Is there a .NET method for doing this? I haven't found anything else that
works.

Thanks

Nov 4 '05 #2
I revised the procedure to use a different query string:

private List<string> GetMappedDrives( string computer )
{
List<string> toReturn = new List<string>();

ConnectionOptions options = new ConnectionOptions();
options.Impersonation =
System.Management.ImpersonationLevel.Impersonate;

//Path for the query, specifying which computer to use
ManagementPath basePath = new ManagementPath( @"\\" + computer +
@"\ROOT\CIMV2" );

ObjectQuery query = new ObjectQuery( "SELECT * FROM
Win32_MappedLogicalDisk" );
ManagementScope scope = new ManagementScope( basePath, options );
ManagementObjectSearcher searcher = new
ManagementObjectSearcher( scope, query );

//Loop through returned drives
foreach ( ManagementObject drive in searcher.Get() )
toReturn.Add( drive.Properties["Name"].Value.ToString() );

return toReturn;
}

"balmerch" wrote:
Add reference to the .net library "System.Management"

Add the using statement:
using System.Management;

Add this procedure:

private List<string> GetMappedDrives( string computer )
{
List<string> toReturn = new List<string>();

ConnectionOptions options = new ConnectionOptions();
options.Impersonation =
System.Management.ImpersonationLevel.Impersonate;

//Path for the query, specifying which computer to use
ManagementPath basePath = new ManagementPath( @"\\" + computer +
@"\ROOT\CIMV2" );

//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_LogicalDisk WHERE DriveType = 4" );

ManagementScope scope = new ManagementScope( basePath, options );
ManagementObjectSearcher searcher = new
ManagementObjectSearcher( scope, query );

//Loop through returned drives
foreach ( ManagementObject drive in searcher.Get() )
toReturn.Add( drive.Properties["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

"lastusernameleft" wrote:
Is there a .NET method for doing this? I haven't found anything else that
works.

Thanks

Nov 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by sandiyan | last post: by
7 posts views Thread by Dean McCarten | last post: by
1 post views Thread by Mark | last post: by
2 posts views Thread by lastusernameleft | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.