ADSI and .Net 
Author Message
 ADSI and .Net

I'm trying to see the shares that users have defined on a computer.  Here is
the code i am trying,

sub main()
    Dim FileService As ActiveDs.IADsFileService
    Dim fileshare As ActiveDs.IADsFileShare
    Dim computername As String
    Dim computerdomain As String

    computerdomain = "hydroque"
    computername = "192.168.1.99"

    FileService = GetObject("WinNT://" & computerdomain & "/" & computername
& "/lanmanserver")

    For Each fileshare In FileService
        MsgBox(fileshare.ADsPath)

    Next

End Sub

I have this running run VB6, but I keep get an error with .net that
Fileservice is not a collection.   What am I missing?



Thu, 28 Apr 2005 09:34:42 GMT  
 ADSI and .Net
So did I. Change it to FService.

Dim FService As ActiveDs.IADsFileService()

Dim fileshare As ActiveDs.IADsFileShare

Dim computername As String

Dim computerdomain As String

computerdomain = "hydroque"

computername = "192.168.1.99"

FService = GetObject("LDAP://" & computerdomain & "/" & computername &
"/lanmanserver")

For Each fileshare In FService

MsgBox(fileshare.ADsPath)

Next

Your next problem should be with the getobject.

HTH


Quote:
> I'm trying to see the shares that users have defined on a computer.  Here
is
> the code i am trying,

> sub main()
>     Dim FileService As ActiveDs.IADsFileService
>     Dim fileshare As ActiveDs.IADsFileShare
>     Dim computername As String
>     Dim computerdomain As String

>     computerdomain = "hydroque"
>     computername = "192.168.1.99"

>     FileService = GetObject("WinNT://" & computerdomain & "/" &
computername
> & "/lanmanserver")

>     For Each fileshare In FileService
>         MsgBox(fileshare.ADsPath)

>     Next

> End Sub

> I have this running run VB6, but I keep get an error with .net that
> Fileservice is not a collection.   What am I missing?



Thu, 28 Apr 2005 09:59:13 GMT  
 ADSI and .Net
Imports System.DirectoryServices

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents ImageList1 As System.Windows.Forms.ImageList

Friend WithEvents viewPC As System.Windows.Forms.TreeView

<System.Diagnostics.De{*filter*}StepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))

Me.viewPC = New System.Windows.Forms.TreeView()

Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)

Me.SuspendLayout()

'

'viewPC

'

Me.viewPC.ImageList = Me.ImageList1

Me.viewPC.Location = New System.Drawing.Point(8, 8)

Me.viewPC.Name = "viewPC"

Me.viewPC.Size = New System.Drawing.Size(416, 536)

Me.viewPC.TabIndex = 0

'

'ImageList1

'

Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit

Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)

Me.ImageList1.ImageStream =
CType(resources.GetObject("ImageList1.ImageStream"),
System.Windows.Forms.ImageListStreamer)

Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)

Me.ClientSize = New System.Drawing.Size(920, 560)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.viewPC})

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim users As New TreeNode("Users")

Dim groups As New TreeNode("Groups")

Dim services As New TreeNode("Services")

viewPC.Nodes.AddRange(New TreeNode() {users, groups, services})

Dim de As DirectoryEntry

de = New DirectoryEntry("WinNT://WorkGroup/Komputerhaus")

Dim child As DirectoryEntry

For Each child In de.Children

Dim newNode As New TreeNode(child.Name)

Select Case child.SchemaClassName

Case "User"

users.Nodes.Add(newNode)

Case "Group"

groups.Nodes.Add(newNode)

Case "Service"

services.Nodes.Add(newNode)

End Select

AddPathAndProperties(newNode, child)

Next

End Sub

Private Sub AddPathAndProperties(ByVal node As TreeNode, ByVal entry As
DirectoryEntry)

node.Nodes.Add(New TreeNode("Path: " & entry.Path))

Dim propertyNode As New TreeNode("Properties")

node.Nodes.Add(propertyNode)

Dim propertyName As String

Dim oneNode As String

For Each propertyName In entry.Properties.PropertyNames

Try

oneNode = propertyName & ": " & _

CType(entry.Properties(propertyName)(0), String)

Catch

oneNode = propertyName & ": " & _

"No text representation."

End Try

propertyNode.Nodes.Add(New TreeNode(oneNode))

Next

End Sub

Private Sub viewPC_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles viewPC.AfterSelect

End Sub

End Class



Thu, 28 Apr 2005 11:10:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Creating NT User accounts using ADSI (WinNT:) within VB.Net

2. VB.Net - ADSI property name with dashes

3. ADSI and VB.NET

4. ADSI & VB.Net

5. Filter ADSI objects in VB.net

6. ADSI and VB .Net

7. Using ADSI in Vb.NET

8. ADSI and VB.NET

9. ADSI code converstion to VB.net

10. VB.NET: Steps for Converting a Windows .NET Application to a Web .NET Application

11. ADO.NET with ASP.NET using VB.NET

12. how to use the system.net.sockets and system.net in VB.net

 

 
Powered by phpBB® Forum Software