WMI Problem

N

Nikolay Petrov

I have an function which should enumerate shares on remote pc.
The problem is the it always shows shares on my local pc.

Code:
Public Function GetNetworkShares(byval ComputerName as string)
As ArrayList
Dim m_Scope as String = "\\" & ComputerName & "\root\cimv2"
Dim RetVal As New ArrayList
Dim ConnOpts As New System.Management.ConnectionOptions
With ConnOpts
.Impersonation = ImpersonationLevel.Impersonate
.Username = m_Username
.Password = m_Password
End With
Dim scope As New ManagementScope(m_Scope, ConnOpts)
Try
scope.Connect()
Dim shareClass As New ManagementClass("Win32_Share")
Dim shares As ManagementObjectCollection =
shareClass.GetInstances()
Dim share As ManagementObject
For Each share In shares
RetVal.Add(share("name").ToString())
Next share
Catch ex As Exception
Throw New Exception(ex.ToString)
End Try
Return RetVal
End Function


No mater what I provide to ComputerName parameter - name or ip address, the
function always returns shares on my local pc.
What's wrong?

TIA
 
P

Peter Falz

Hi Nikolay,

you have to set your managementScope to the
managementClass.

shareClass.Scope = scope

HTH

Bye
Peter

Nikolay Petrov said:
I have an function which should enumerate shares on remote pc.
The problem is the it always shows shares on my local pc.

Code:
Public Function GetNetworkShares(byval ComputerName as string)
As ArrayList
Dim m_Scope as String = "\\" & ComputerName & "\root\cimv2"
Dim RetVal As New ArrayList
Dim ConnOpts As New System.Management.ConnectionOptions
With ConnOpts
.Impersonation = ImpersonationLevel.Impersonate
.Username = m_Username
.Password = m_Password
End With
Dim scope As New ManagementScope(m_Scope, ConnOpts)
Try
scope.Connect()
Dim shareClass As New ManagementClass("Win32_Share")

shareClass.Scope = scope
 

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

Top