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)
isMember = False
The below is how i call that function:
IsMemberOfGroup(localusrname, TextBox1.Text, "administrators")
Rather than write the result to the msgbox, i want to write it to tbadmincheck.text, any way to do that?