Find open files on shares (WMI?)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I want to programmatically discover what users are connecting to the
shared folders and files on my PC (WinXP and up). I want essentially the
same info you get by opening the Computer Managerment console, looking at
"Shared Folders" and clicking in the "Sessions" and "Open Files" folders in
there.

It shows domain user, the connection host name or IP address and the names
of open files. I was hoping something simple like a WMI query could do this,
but the WMI objects I've looked into don't support this under Windows Server
2003. I would appreciate any pointers as to how to get this info, thanks!

Richard
 
Richard A. Lowe said:
Hi, I want to programmatically discover what users are connecting to the
shared folders and files on my PC (WinXP and up). I want essentially the
same info you get by opening the Computer Managerment console, looking at
"Shared Folders" and clicking in the "Sessions" and "Open Files" folders
in
there.

It shows domain user, the connection host name or IP address and the names
of open files. I was hoping something simple like a WMI query could do
this,
but the WMI objects I've looked into don't support this under Windows
Server
2003. I would appreciate any pointers as to how to get this info, thanks!


Richard,

I believe the following code should do the trick, but on my pc it is only
displaying the C$ file share (most of the time):


ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT *
FROM Win32_ConnectionShare");
foreach (ManagementObject connectionShare in searcher.Get())
{
// Win32_Share
string antecedent = connectionShare["Antecedent"].ToString();
Console.WriteLine("Antecedent: " + antecedent);
ManagementObject share = new ManagementObject(antecedent);

// Win32_ServerConnection
string dependant = connectionShare["Dependent"].ToString();
Console.WriteLine("Dependant: " + dependant);
ManagementObject connection = new ManagementObject(dependant);
Console.WriteLine(share["Name"].ToString());

if (connection != null && connection["Name"] != null)
Console.WriteLine(connection["Name"].ToString());

Console.WriteLine("\n");
}



hth
andrew
 
"the fuzz" <yeah g'day> wrote in message

.......

I believe the following code should do the trick, but on my pc it is only
displaying the C$ file share (most of the time):

I should mention that my code only showed the shares that had connections,
if you wish to simply enumerate the shares you can execute the following
query SELECT * FROM Win32_Share

andrew
 
Back
Top