473,657 Members | 2,579 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 12148
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

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>();

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" );

ObjectQuery query = new ObjectQuery( "SELECT * FROM
Win32_MappedLog icalDisk" );
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;
}

"balmerch" wrote:
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

Nov 4 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1621
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 on the remote machine. From my local machine(currently on Unix), I want to Run a java GUI that will invoke test.BAT on the remote machine, which will install
5
15061
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
5856
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: ProductDescription.htm#file:\\DBHOST\C$\Documents and Settings\Administrator\My Documents\Products\Documents\ProductDescription.htm Having the hyperlink in this format allows the document to be opened by anyone on the local area network.
7
1920
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 need to try and finish this toda Thanks in Advanc Dean McCarte ASP/VBS/VB.NET & ASP.NET Develope Cumbria U
1
2788
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 mapped drive ever gets disconnected (remote machine reboot), the drive is disconnected. When the remote machine comes back up, the mapped drive generally stays disconnected(red x). But all it takes is a F5 keypress in explorer to make the drives...
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
3570
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 clicks on the "Browse" button on the "<input type="File"... control and selects a file located in one of many possible mapped drives. I want to save the location of the file as a path as you would see when mapping a drive. For instance,...
0
1549
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 call from a regular Windows application, all of the drives are returned. Any thoughts on why the mapped drives are not returned when the call is made from a windows service? The windows service is running under a domain user account with admin...
14
5402
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 sequence: 1. create object of class 2. call mappeddrives() method 3. call impersonate method then its working fine.
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1607
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.