Getting remote drives

D

Daniel

Any ideas why the below function does not work? It just returns the
drives of the local computer not the remote one. I don't think it is
permissions because I am in the Admins group on the remote computer.



Private Function GetRemoteDrives(ByVal RemoteServer As String) As String

Dim moMOS As System.Management.ManagementObjectSearcher
Dim moObject As System.Management.ManagementObject
Dim moQuery As System.Management.ObjectQuery
Dim moResults As System.Management.ManagementObjectCollection
Dim moScope As System.Management.ManagementScope
Dim AllDrives As String = Nothing

moScope = New Management.ManagementScope("\\" & RemoteServer)
moQuery = New Management.ObjectQuery("Select Name from Win32_LogicalDisk
where DriveType=3")
moMOS = New Management.ManagementObjectSearcher(moScope, moQuery)

moResults = moMOS.Get

For Each moObject In moResults

AllDrives = AllDrives + moObject("Name") & "|"

Next

Return Strings.Left(AllDrives, Len(AllDrives) - 1)

End Function
 
K

Ken Tucker [MVP]

Hi,

I dont see where you connect to moscope.

http://msdn.microsoft.com/library/d...systemmanagementmanagementscopeclasstopic.asp

Ken
-----------------
Any ideas why the below function does not work? It just returns the
drives of the local computer not the remote one. I don't think it is
permissions because I am in the Admins group on the remote computer.



Private Function GetRemoteDrives(ByVal RemoteServer As String) As String

Dim moMOS As System.Management.ManagementObjectSearcher
Dim moObject As System.Management.ManagementObject
Dim moQuery As System.Management.ObjectQuery
Dim moResults As System.Management.ManagementObjectCollection
Dim moScope As System.Management.ManagementScope
Dim AllDrives As String = Nothing

moScope = New Management.ManagementScope("\\" & RemoteServer)
moQuery = New Management.ObjectQuery("Select Name from Win32_LogicalDisk
where DriveType=3")
moMOS = New Management.ManagementObjectSearcher(moScope, moQuery)

moResults = moMOS.Get

For Each moObject In moResults

AllDrives = AllDrives + moObject("Name") & "|"

Next

Return Strings.Left(AllDrives, Len(AllDrives) - 1)

End Function
 
D

Daniel

Ken said:
Hi,

I dont see where you connect to moscope.

http://msdn.microsoft.com/library/d...systemmanagementmanagementscopeclasstopic.asp

Ken
-----------------
Any ideas why the below function does not work? It just returns the
drives of the local computer not the remote one. I don't think it is
permissions because I am in the Admins group on the remote computer.



Private Function GetRemoteDrives(ByVal RemoteServer As String) As String

Dim moMOS As System.Management.ManagementObjectSearcher
Dim moObject As System.Management.ManagementObject
Dim moQuery As System.Management.ObjectQuery
Dim moResults As System.Management.ManagementObjectCollection
Dim moScope As System.Management.ManagementScope
Dim AllDrives As String = Nothing

moScope = New Management.ManagementScope("\\" & RemoteServer)
moQuery = New Management.ObjectQuery("Select Name from Win32_LogicalDisk
where DriveType=3")
moMOS = New Management.ManagementObjectSearcher(moScope, moQuery)

moResults = moMOS.Get

For Each moObject In moResults

AllDrives = AllDrives + moObject("Name") & "|"

Next

Return Strings.Left(AllDrives, Len(AllDrives) - 1)

End Function

thanks, i'll look into it. any tips?
 

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