Hey Guys,
Here's my code - for some reason, the message boxes aren't showing when I run the application. However, it shows up fine when I click the button on the form. Any idea why this would happen? Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
namespace REG_Asset_Checkout
{
public partial class main_Form : Form
{
public main_Form()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void main_Form_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'reg_checkoutDataSet.Laptops' table. You can move, or remove it, as needed.
this.laptopsTableAdapter.Fill(this.reg_checkoutDataSet.Laptops);
// Create the context for the principal object.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");
// Retrieve the group principal object for the group you need.
GroupPrincipal groupPrincipal =
GroupPrincipal.FindByIdentity(ctx, "Domain Admins");
// Check to see if this user is a member of the "Administrators" group.
bool isMember = UserPrincipal.Current.IsMemberOf(groupPrincipal);
if (isMember)
{
button1.Enabled = true;
MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
button1.Enabled = false;
MessageBox.Show("You are not a Domain Admin - Controls locked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}