views:

20

answers:

1

On this winform application I am writing, I want to secure one menu item from most users. It runs a month-end and cannot be easily backed out if accidentally run. The menu option opens up a window to prompt the user for some information before processing. I don't care where exactly I do the check, but I want to be sure only certain users can run this function.

A Google search (on my question title above) didn't turn up anything obvious. Can anyone point me in a direction to pick up who is signed into Windows and how to check if they are authorized?

+3  A: 

This page has some code for getting user details and checking them.

This code:

public string GetloggedinUserName()
{
    System.Security.Principal.WindowsIdentity currentUser =
                      System.Security.Principal.WindowsIdentity.GetCurrent();
    return currentUser.Name;
}

returns the current user name. You could use this to check against your list of authorised users.

More details on the WindowsIdentityclass can be found here.

It has a Groups property which you could use to check for membership of a group rather than having to check individual users.

ChrisF
I'll have to talk to others in the department to see what method they prefer.
Mike Wills