0

Using VB.NET 2010:

I'm making a simple "launcher" application for our work applications. I have already created the ToolStripMenu that contains the menus I want. They will be arranged like so:

File | Dept 1 | Dept 2 | Dept 3 | Admin | Help

What I need to do, is restrict access to the Admin menu, based on the Environment.UserName variable. Ideally, I would like to have it not even render - but if the only option is to have it greyed out, I am okay with that as well.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Mitch Brown
  • 25
  • 1
  • 5

1 Answers1

1
    public Form1() {
        InitializeComponent();
        var id = System.Security.Principal.WindowsIdentity.GetCurrent();
        var prince = new System.Security.Principal.WindowsPrincipal(id);
        adminToolStripMenuItem.Visible = prince.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
    }

There are a rather large number of ways that a LAN admin can move that cheese. You can tell from the very awkward code I posted. Querying the domain controller with the classes in the System.DirectoryServices is often necessary.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536