Solved

vb.net and functions

Posted on 2014-12-08
3
108 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

22 Experts available now in Live!

Get 1:1 Help Now