473,508 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12127
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
1610
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
15046
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
5835
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
1916
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
2774
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
602
by: lastusernameleft | last post by:
Is there a .NET method for doing this? I haven't found anything else that works. Thanks
2
3561
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
1539
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
5358
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...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.