Re: simple managementobject question
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 15 Oct 2007 18:47:28 +0200
"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.
.
- Follow-Ups:
- Re: simple managementobject question
- From: DBC User
- Re: simple managementobject question
- References:
- simple managementobject question
- From: DBC User
- simple managementobject question
- Prev by Date: solution does not run after upgrading assemblies
- Next by Date: dropdown list box
- Previous by thread: simple managementobject question
- Next by thread: Re: simple managementobject question
- Index(es):
Relevant Pages
|