Find drives in the PC

  • Thread starter Thread starter DBC User
  • Start date Start date
D

DBC User

I have a program in the network location, which when running, it needs
to find out what are all the drives available in the PC. I have the
following code in my program

using (ManagementClass netwConn = new
ManagementClass("Win32_NetworkConnection"))
{
ManagementObjectCollection shares =
netwConn.GetInstances();
foreach (ManagementObject share in shares)
{
Console.WriteLine("{0} - {1}", share["LocalName"],
share["RemotePath"]);
if (path.Equals(share["RemotePath"].ToString()))
return share["LocalName"].ToString();
}
return "";
}
I realised that since the application is invoked from the server, it
might be trying to find the drives in the server insteaded of my PC.
Is this a correct if so, how can I identify all the drives available
in the PC itself instead of Server?
 
DBC User said:
I have a program in the network location, which when running, it needs
to find out what are all the drives available in the PC. I have the
following code in my program

using (ManagementClass netwConn = new
ManagementClass("Win32_NetworkConnection"))
{
ManagementObjectCollection shares =
netwConn.GetInstances();
foreach (ManagementObject share in shares)
{
Console.WriteLine("{0} - {1}", share["LocalName"],
share["RemotePath"]);
if (path.Equals(share["RemotePath"].ToString()))
return share["LocalName"].ToString();
}
return "";
}
I realised that since the application is invoked from the server, it
might be trying to find the drives in the server insteaded of my PC.
Is this a correct if so, how can I identify all the drives available
in the PC itself instead of Server?


You can use System;IO.GetDrives to retrieve the *local* disk drives actually
connected to your system.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top