Re: simple managementobject question

Tech-Archive recommends: Fix windows errors by optimizing your registry



"DBC User" <dbcuser@xxxxxxxxx> wrote in message news:1192465659.105138.274650@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.



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.

.



Relevant Pages

  • Re: simple managementobject question
    ... particular drive or I have a unc path, I need to find the drive. ... drives. ... ManagementObjectCollection shares = netwConn.GetInstances; ... Check the WMI docs for more details, and use wbemtest.exe to experiment with ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: USE MACRO TO SAVE WORKSHEET SELECTING FILENAME FROM CELLS
    ... By using a UNC path you're specifying directly where on the network a file you should be saved - rather than relying on the drive mapping. ... You don't really need want to occupy too much of the user's screen real estate and to be tidy, you should hide or delete them when you close or deactivate your workbook - that's a bit of fathing around for no real gain in this instance. ... that could take a while to scour all the available drives. ...
    (microsoft.public.excel.programming)
  • Re: UNC path versus mapped drives
    ... same UNC path you used to map the drive. ... Disconnected drives can be for a variety of ... for that same user on the computer that is sharing the folder. ...
    (microsoft.public.win2000.networking)
  • Re: Linking to _be tables
    ... You only have to set up the UNC path once in the Linked Table Manager. ... The UNC path is always the same for all users, regardless of what drives they ... The function in this code that will translate a drive letter to a UNC path ... Dave Hargis, Microsoft Access MVP ...
    (microsoft.public.access.gettingstarted)
  • RE: Hyperlinking in 97 and 2000 code?
    ... you drive letter to the UNC path so avoid this issue alltogether. ... "CarolM" wrote: ... users have the drives mapped under different letters. ... On a form called frmdaily i have 2 hyperlink fields - these basically link ...
    (microsoft.public.access.formscoding)