Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

simple managementobject question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DBC User - 15 Oct 2007 17:27 GMT
Hi all,

I am in a situation where I need to find the a unc path of a
particular drive or I have a unc path, I need to find the drive.
Either way will work. I do not want to use dllimport to make the win32
api call. So after some research I found out that I could use
ManagementObjects

using (ManagementObjectSearcher DiskSearch =
               new ManagementObjectSearcher(new
                 SelectQuery("Select * from Win32_LogicalDisk")))
               {
                   using (ManagementObjectCollection moDiskCollection
=

DiskSearch.Get())
                   {
                       foreach (ManagementObject mo in
moDiskCollection)
                       {
                           mo.Dispose();
                       }
                   }
               }

This works and I was able to find all the drives in the box instead of
going through 'A' thru 'Z', but I did not find the UNC path of these
drives. Does any one know how to go about getting  the unc path?

Thanks.
Willy Denoyette [MVP] - 15 Oct 2007 17:47 GMT
> Hi all,
>
[quoted text clipped - 26 lines]
>
> Thanks.

Check the Win32_NetworkConnection class, it has all properties you are
looking for.

 using(ManagementClass netwConn = new
ManagementClass("Win32_NetworkConnection" ))
 {
  ManagementObjectCollection shares = netwConn.GetInstances();
  foreach(ManagementObject share in shares )
   Console.WriteLine("{0} - {1}",share["LocalName"],share["RemotePath"]);
 }

Check the WMI docs for more details, and use wbemtest.exe to experiment with
WMI before using in your code..

Willy.
DBC User - 15 Oct 2007 19:36 GMT
On Oct 15, 11:47 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:

> > Hi all,
>
[quoted text clipped - 44 lines]
>
> - Show quoted text -

Thank you very much for the answer, it helps.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.