none
User account rights RRS feed

  • Question

  • Hi,

    I want to restrict users that are logged on a computer from a guest account from running my .NET C# application. What is the recommended way to do this?

    Best Regards
    Olof

    Tuesday, January 18, 2011 8:27 AM

Answers

  • .NET supports Role-Based Security, so you may check whether current user is a guest using following code snippet:

     

                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

                WindowsIdentity wid = Thread.CurrentPrincipal.Identity as WindowsIdentity;

                if (wid == null || wid.IsGuest)

                {

                    // The user is a guest, attempt to access is denied.

                    return;

                }

                else

                {

                    // The user is not a guest.

                    Do();

                }


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Tuesday, January 25, 2011 9:08 AM
    Wednesday, January 19, 2011 5:18 AM

All replies

  • Hi OlofC,

     

    Perhaps you would find this article helpful?

     

    http://www.codeproject.com/KB/security/UB_CAS_NET.aspx

     

    All the best,

     

    Roger

    Tuesday, January 18, 2011 8:52 PM
  • .NET supports Role-Based Security, so you may check whether current user is a guest using following code snippet:

     

                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

                WindowsIdentity wid = Thread.CurrentPrincipal.Identity as WindowsIdentity;

                if (wid == null || wid.IsGuest)

                {

                    // The user is a guest, attempt to access is denied.

                    return;

                }

                else

                {

                    // The user is not a guest.

                    Do();

                }


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Tuesday, January 25, 2011 9:08 AM
    Wednesday, January 19, 2011 5:18 AM