try
{
string gr1 = @"LENOVO-IDEAPAD3\Group_1";
string gr2 = @"LENOVO-IDEAPAD3\Group_2";
string gr3 = @"LENOVO-IDEAPAD3\Group_3";
IntPtr th = IntPtr.Zero;
WindowsIdentity.Impersonate(th);
bool log = LogonUser(txtLogin.Text, "workgroup", txtPassword.Text, 2, 0, ref th);
if (log)
{
MessageBox.Show("Успех", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal currentUser = new WindowsPrincipal(MyIdentity);
if (currentUser.IsInRole(gr1) == true)
{
MessageBox.Show($"Пользователь входит Group1");
textBox1.Text = "Текст информации";
}
if (currentUser.IsInRole(gr2)==true)
{
MessageBox.Show($"Пользователь входит Group2");
textBox1.ReadOnly = true;
}
if (currentUser.IsInRole(gr3) == true)
{
MessageBox.Show($"Пользователь входит Group3");
textBox1.Visible = false;
}
}
else
{
MessageBox.Show("Неудача", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error);
}