Solved

vb.net and functions

Posted on 2014-12-08
3
112 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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