title: List Server Shares
body: <p>I am trying to list the Shares on a Server like so:
  <a href="https://i.stack.imgur.com/L5jQH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L5jQH.png" alt="enter image description here"></a></p>
  
  <p>I tried the following code:</p>
  
  <pre><code>    Dim objWMIService = GetObject("winmgmts:\\srv0000\root\CIMV2")
      Dim colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share")
  
      For Each objShare In colShares
          MsgBox("Name: " &amp; objShare.Name)
      Next
  </code></pre>
  
  <p>But I get an error <strong>Cannot create ActiveX component.</strong> on line 1.</p>
  
  <p>So I tried:</p>
  
  <pre><code>    Dim scope As ManagementScope = New ManagementScope("\\srv0000\root\CIMV2")
      scope.Connect()
      Dim worker As ManagementObjectSearcher = New ManagementObjectSearcher(scope, New ObjectQuery("SELECT * FROM win32_share"))
      For Each share As ManagementObject In worker.Get
          MsgBox(share("Name"))
      Next
  </code></pre>
  
  <p>But I get the error <strong>Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))</strong> on line 2.</p>
  
  <p>I do have access to the server as is shown in the photo above, but am not an administrator. I'd just like to list the Shares as explorer can. As I don't need to make edits to the Shares, is there another approach I can take that's less robust?</p>
  
  <p>Thanks!</p>