Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 117
  • Last Modified:

vb.net and functions

I am trying to use a function to check if a remote user is a part of their workstations local admin group and it works fine.  I am trying to write the result to a textbox i have on the form and it looks like functions do not like any form controls for some reason???

Public Shared Function IsMemberOfGroup(userName As String, machineName As String, memberGroup As String) As Boolean
        Dim isMember As Boolean = False
        Using rootContext As New PrincipalContext(ContextType.Machine, machineName), _
              grp As GroupPrincipal = GroupPrincipal.FindByIdentity(rootContext, memberGroup), _
              usr As UserPrincipal = UserPrincipal.FindByIdentity(rootContext, IdentityType.SamAccountName, userName)
            If grp IsNot Nothing AndAlso usr IsNot Nothing Then
                ' Check if the user is a member of the group.
                isMember = grp.GetMembers(True).Contains(usr)
                MsgBox("yay")
            Else
                isMember = False
                MsgBox("nah")
            End If
        End Using
        Return isMember
    End Function

Open in new window


The below is how i call that function:
IsMemberOfGroup(localusrname, TextBox1.Text, "administrators")

Open in new window


Rather than write the result to the msgbox, i want to write it to tbadmincheck.text, any way to do that?
0
derek7467
Asked:
derek7467
  • 2
1 Solution
 
dustockCommented:
What error do you get when you try to assign the result to a textbox?  Are you trying to write the 'yay' or 'nah' result to the text box?  Have you tried to do something like

If IsMemberOfGroup(localusrname, TextBox1.Text, "administrators") Then
   tbadmincheck.Text = "yay"
Else
   tbadmincheck.Text = "nah"
End If

Open in new window

0
 
derek7467Author Commented:
I didnt even think to do it like that.  Ugh, i hate when i think to deep into simple fixes.  Thanks!
0
 
dustockCommented:
It happens to the best of us :)

Glad I was able to help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now