Solved

vb.net and functions

Posted on 2014-12-08
3
107 Views
Last Modified: 2014-12-08
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
Comment
Question by:derek7467
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 40487015
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
 

Author Closing Comment

by:derek7467
ID: 40487102
I didnt even think to do it like that.  Ugh, i hate when i think to deep into simple fixes.  Thanks!
0
 
LVL 9

Expert Comment

by:dustock
ID: 40487131
It happens to the best of us :)

Glad I was able to help!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now