View Single Post
  #3 (permalink)  
Old 06-08-2009, 9:14 AM
grmbl's Avatar
grmbl grmbl is offline
VB.NET Forum Enthusiast
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Jun 2009
Location: Belgium
Age: 27
Posts: 32
Reputation: 12
grmbl is on a distinguished programming path ahead
Default

This does the trick BUT only when your administrator!!!!
Google impersonating vb.net wmi and you'll find a solution for non-admin users.

Code:
' also import these through project - add reference...
Imports System.Management
Imports System.IO

Public Function GetShares(ByVal Machine As String) As DataSet
        On Error Resume Next

        Dim ds_shares As New DataSet
        Dim scope As New ManagementScope("\\" + Machine + "\root\cimv2")
        scope.Connect()

        Dim objectQuery As New ObjectQuery("select * from Win32_Share")
        Dim searcher As New ManagementObjectSearcher(scope, objectQuery)
        Dim os As ManagementObject
        Dim sXML As String
        Dim sep As String = vbCrLf
        sXML = "<ServerInfo>"
        Dim moColl As ManagementObjectCollection = searcher.Get()

        For Each os In moColl
            sXML = sXML & sep & "<Information Field='Share' Value='" & os("name") & " (" & os("path") & ")'/>"
        Next os

        sXML += "</ServerInfo>"
        Dim SR As New StringReader(sXML)
        ds_shares.ReadXml(SR)

        Return ds_shares
End Function

'usage
Dim ds As DataSet = GetShares("servername")

For Each r As DataRow In ds.Tables(0).Rows
   MsgBox(r.Item("Value"))
Next
If you put a breakpoint on the line where the dataset is declared and you debug, you can select the word "ds" and a tooltip will
come up with everything about this dataset. There's also a magnifier, if you click on it you can SEE the dataset!

Hope that helps you on your way!
__________________
"The world is coming to an end... SAVE YOUR BUFFERS !"
Reply With Quote