I am trying to list the Shares on a Server like so:
I tried the following code:
Dim objWMIService = GetObject("winmgmts:\\srv0000\root\CIMV2")
Dim colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share")
For Each objShare In colShares
MsgBox("Name: " & objShare.Name)
Next
But I get an error Cannot create ActiveX component. on line 1.
So I tried:
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
But I get the error Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) on line 2.
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?
Thanks!
User contributions licensed under CC BY-SA 3.0