Today, I will teach you how to create a program that displays the Windows User Properties in VB.NET. It will have Windows user properties like Username, Guest User, System, Anonymous, Authentication, Impersonation Level, Authentication Type, Groups, Owner Value, User Value, and Token Size.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to
File, click
New Project, and choose
Windows Application.
2. Next, add only one TextBox named
TextBox1.
3. Now, we will do the coding.
First, import the
System.Security library to access the Principal keyword that will be used for accessing the windows identity.
Then code for the Form Load.
To access the username who logged in your PC. Have this code:
TextBox1.Text = "- Username: " + Principal.WindowsIdentity.GetCurrent.Name
To determine if it is a guest user or not. Have this code:
If Principal.WindowsIdentity.GetCurrent.IsGuest = "false" Then
TextBox1.Text = TextBox1.Text & vbCrLf & "- Not Guest User"
Else
TextBox1.Text = TextBox1.Text & vbCrLf & "- Guest User"
End If
To determine if it is a system user or not. Have this code:
If Principal.WindowsIdentity.GetCurrent.IsSystem = "false" Then
TextBox1.Text = TextBox1.Text & vbCrLf & "- Not System"
Else
TextBox1.Text = TextBox1.Text & vbCrLf & "- System"
End If
To determine if it is an anonymous user or not. Have this code:
If Principal.WindowsIdentity.GetCurrent.IsAnonymous = "false" Then
TextBox1.Text = TextBox1.Text & vbCrLf & "- Not Anonymous"
Else
TextBox1.Text = TextBox1.Text & vbCrLf & "- Anonymous"
End If
To determine if it is an authenticated or not. Have this code:
If Principal.WindowsIdentity.GetCurrent.IsAuthenticated = "false" Then
TextBox1.Text = TextBox1.Text & vbCrLf & "- Not Authenticatedr"
Else
TextBox1.Text = TextBox1.Text & vbCrLf & "- Authenticated"
End If
To determine the Impersonation Level. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- Impersonation Level: " & Principal.WindowsIdentity.GetCurrent.ImpersonationLevel
To determine the Authentication Type. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- Authentication Type: " & Principal.WindowsIdentity.GetCurrent.AuthenticationType.ToString
To determine the Groups. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- Groups: " & Principal.WindowsIdentity.GetCurrent.Groups.ToString
To determine the Owner Value. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- Owner Value: " & Principal.WindowsIdentity.GetCurrent.Owner.Value.ToString
To determine the User Value. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- User Value: " & Principal.WindowsIdentity.GetCurrent.User.Value.ToString
To determine the Token Size. Have this code:
TextBox1.Text = TextBox1.Text & vbCrLf & "- Token Size: " & Principal.WindowsIdentity.GetCurrent.Token.Size
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware