473,387 Members | 1,542 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,387 software developers and data experts.

C# .Net Getting Network Drive Path

Hi there. I am able to get the list fo drives connected to a pc using a windows app i have developed using Visual Studio 2005. I am able to get the list of Network Drives however, i cannot get the "network path" for the drives??
Any ideas as to how i can get this??
Thank you....
Jul 28 '08 #1
3 8195
Plater
7,872 Expert 4TB
Well there is this way, it's kinda slow.
You might be able to trim up the query for it though.
Expand|Select|Wrap|Line Numbers
  1. public static string NetworkConnection()
  2. {
  3.     StringBuilder st = new StringBuilder();
  4.     ObjectQuery oq = new ObjectQuery("select Name, RemotePath from Win32_NetworkConnection");
  5.     ManagementScope scope = new ManagementScope("\\root\\cimv2");
  6.     scope.Connect();
  7.     ManagementObjectSearcher sea = new ManagementObjectSearcher(scope, oq);
  8.     /*
  9.     UInt32[] AccessMask;
  10.     string Caption;
  11.     string Comment;
  12.     string ConnectionState;
  13.     string ConnectionType;
  14.     string Description;
  15.     string DisplayType;
  16.     DateTime InstallDate;
  17.     string LocalName;
  18.     string Name;
  19.     bool Persistent;
  20.     string ProviderName;
  21.     string RemoteName;
  22.     string RemotePath;
  23.     string ResourceType;
  24.     string Status;
  25.     string UserName;
  26.     */
  27.     ManagementObjectCollection moc = sea.Get();
  28.     st.AppendFormat("Network Connection Count={0}\r\n\r\n", moc.Count);
  29.     foreach (ManagementObject proc in moc)
  30.     {
  31.         st.AppendFormat("   Name={0}\r\n", proc["Name"]);
  32.         st.AppendFormat("   RemotePath={0}\r\n", proc["RemotePath"]);
  33.         st.AppendFormat("\r\n");
  34.     }
  35.     return st.ToString();
  36. }
  37.  
Jul 28 '08 #2
Thanks...

Will try it!!
Jul 29 '08 #3
Well there is this way, it's kinda slow.
You might be able to trim up the query for it though.
Expand|Select|Wrap|Line Numbers
  1. public static string NetworkConnection()
  2. {
  3.     StringBuilder st = new StringBuilder();
  4.     ObjectQuery oq = new ObjectQuery("select Name, RemotePath from Win32_NetworkConnection");
  5.     ManagementScope scope = new ManagementScope("\\root\\cimv2");
  6.     scope.Connect();
  7.     ManagementObjectSearcher sea = new ManagementObjectSearcher(scope, oq);
  8.     /*
  9.     UInt32[] AccessMask;
  10.     string Caption;
  11.     string Comment;
  12.     string ConnectionState;
  13.     string ConnectionType;
  14.     string Description;
  15.     string DisplayType;
  16.     DateTime InstallDate;
  17.     string LocalName;
  18.     string Name;
  19.     bool Persistent;
  20.     string ProviderName;
  21.     string RemoteName;
  22.     string RemotePath;
  23.     string ResourceType;
  24.     string Status;
  25.     string UserName;
  26.     */
  27.     ManagementObjectCollection moc = sea.Get();
  28.     st.AppendFormat("Network Connection Count={0}\r\n\r\n", moc.Count);
  29.     foreach (ManagementObject proc in moc)
  30.     {
  31.         st.AppendFormat("   Name={0}\r\n", proc["Name"]);
  32.         st.AppendFormat("   RemotePath={0}\r\n", proc["RemotePath"]);
  33.         st.AppendFormat("\r\n");
  34.     }
  35.     return st.ToString();
  36. }
  37.  
Thanks Plater...it works brilliant!!!! :-)
Aug 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: giloosh99 | last post by:
Hello, Im grabbing tables via VB code using visual foxpro ODBC drives. The tables directory is in a mapped network drive. The code works fine and does the job, however if the computer is idle for...
1
by: Max Baki via .NET 247 | last post by:
I all, i've write a sample ftp Windows service which download files and copy them on remote share or remote mapped drive (the service works fine on local drives). This part of code is the...
5
by: Nirosh | last post by:
Hi All, Can any one suggest me a best way to do this .. I have a thrid party tool "EXE" that we need to use with our web service to manipulate some complex XML files, which reside in a...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
2
by: .Net Believer | last post by:
I using the routine below to copy file to a network drive for a regular backup process. Before calling this routine I using another function to check the presence of the LAN connection and the...
10
by: mukeshhtrivedi | last post by:
Hi, I have some MDB (MS Access 2000) files on our server. It is small application created by one of our employee long time ago. I see this application is on Network Drive G: and H: (both drive has...
2
by: Mike | last post by:
Can a vb program running as a serice not use network paths to do file/io? I can't seem to get my program to work with network paths and files. When I use local disk it works fine. When I run it...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
4
by: rony_16 | last post by:
Hi , I am writing a program that part of than program if to add a new network drive to the user. The adding part i know how to do (by win api "WNetAddConnection2A") but i want to check first if...
18
by: Aaron Gray | last post by:
Has anyone got a code snippet to separate out the path components, ie drive, path, filename, and extension ? Many thanks in advance, Aaron
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.