Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm trying to create a web page which allows me to list the members of the local Administrators group of a client system. I found some code parts which can list the members (using WMI) but these cannot add or remove members from the group. I switched to using a DirectoryEntry object but when I run the code below, only one account is returned although the administrators group contains more (both local and domain) accounts. (note that txtOutput is a textbox on my webpage). Can someone help me out?

 

       Dim strComputer As String = "computer"
       Dim strAccount As String = "administrator"
       Dim strPassword As String = "secret"

       Dim locPath As String = "WinNT://" & strComputer & "/Administrators,group"

       Dim localGroup As DirectoryEntry
       localGroup = New DirectoryEntry(locPath, strComputer & "\" & strAccount, strPassword)

       Dim allMembers As Object = localGroup.Invoke("Members")
       Dim groupMember As Object

       For Each groupMember In CType(allMembers, IEnumerable)
           Dim member As New DirectoryEntry(groupMember)
           txtOutput.Text = txtOutput.Text & member.Path & vbCrLf
       Next

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...