Solved

vb.net and functions

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Footer for each row on Gridview 2 39
Help with exporting to excel 4 44
VB.NET 2008 - SQL Timeout 9 49
Code enhancement 4 32
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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