title: How to get current connections to resources on a server with C# (similar to output from the "net file" command)
body: <p>In command prompt, if <code>net file</code> is executed, it shows the resources that are open over any shared folders and it also shows the user name that is accessing the resource.</p>
  
  <p>Example:
  <a href="https://i.stack.imgur.com/K3dnC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K3dnC.png" alt="net file example"></a></p>
  
  <p>The same information can be viewed from Computer Management (compmgmt.msc) -> System Tools -> Shared Folders -> Open Files.</p>
  
  <p>Example:
  <a href="https://i.stack.imgur.com/K3L7w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K3L7w.png" alt="computer management open files example"></a></p>
  
  <p>The same information can be accessed using a VBScript:</p>
  
  <pre><code>Set objConnection = GetObject("WinNT://localhost/LanmanServer")
  Set colResources = objConnection.Resources
  For Each objResource in colResources
      Wscript.Echo "Path: " &amp; objResource.Path
      Wscript.Echo "User: " &amp; objResource.User
      Wscript.Echo
  Next
  </code></pre>
  
  <p>How can this same information by accessed via C#? (without running the <code>new file</code> command from C# - this would truncate long path names in resources).</p>
  
  <p>Is it possible to get to this information using WMI (which class? - I believe <code>Win32_ServerConnection</code> doesn't give the path of the resources that are open; same with <code>Win32_ServerSession</code>) or Netapi32.dll? If so, how can this be done?</p>
  
  <p><strong>Note:</strong> Need a way to get the <strong>full path</strong> of the file that is opened similar to the information in the screenshots from command prompt and computer management.</p>
  
  <p>Any ideas?</p>