473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 12103
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sandiyan | last post by:
Hi, I am trying to use java to do the following: Remote machine(Windows): Has a drive mapped(m:\) to a network share. Invoking a BAT file(test.BAT) from this drive will install an application...
5
by: Roger | last post by:
I would like to get a list of running processes on a remote machine. How is this possible via VB.Net? Is it possible? Can someone point me in the right direction. thanks, rog
6
by: deko | last post by:
In a multi-user environment, I have a table that stores hyperlinks to documents that are stored on the machine that hosts the mdb database. The table entry looks like this: ...
7
by: Dean McCarten | last post by:
I Need to Retrieve the UNC Path of Mapped Drives on a Client Machine's (NT4 + y2k) on my Network, but I have been unsuccessful so far and I find seem to find a way to do this, any idea anyone I...
1
by: Mark | last post by:
I posted this question some time ago, but didn't get a response. So, I'll try again. Hello, I have a VB.NET app which polls mapped drives periodically looking for files. However, if the...
2
by: lastusernameleft | last post by:
Is there a .NET method for doing this? I haven't found anything else that works. Thanks
2
by: Ben | last post by:
Hi, Thanks for reading this post... I am trying to get the computer/server names from the mapped drives on the Clients PC when they select a file from the upload "browse" button. When the user...
0
by: rmckbrown | last post by:
Using .Net FW 1.1 and VB.net I am calling system.io.directory.getlogicaldrives from a windows service; however, only the local drives are returned, and not my mapped drives. When I execute the...
14
AnuSumesh
by: AnuSumesh | last post by:
Hi all, I am writing one application using c# in which firstly I m getting impersonating the user and then i want to retrieve mapped Drives. But issue is when I am calling method in following...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.