CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Location
    Ireland
    Posts
    1

    PROBLEM WITH WindowsPrincipal

    I created a New Group Called AppOperators under
    Computer Management => Local Users and Groups => Groups

    I then added my account into the AppOperator Group, after adding. I refreshed the window using Action => Refresh.

    When i run the below code, i am getting the value as False for "Is in AppOperators group". And when i restarted the PC it worked fine (i.e. it returned the value as True)

    I have performed this steps several times, but to get the Correct value I have to re-boot the machine.

    I have tested the below code on WinXP Professional and Windows 2000 Advance Server with latest SP installed.

    I am using VS.NET Version 2002.
    Framework Version: 1.0.3705 with SP2 installed.

    Am missing something or am i performing any steps incorrectly?
    Any information on this would be very helpful.

    ----------------------------------------------------------
    Code:
    ----------------------------------------------------------
    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)

    Dim user As WindowsPrincipal = CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)

    Dim sbDetail As New StringBuilder()

    With sbDetail
    .AppendFormat("User name: {0}", user.Identity.Name & ControlChars.CrLf)
    .AppendFormat("Authentication type: {0}", user.Identity.AuthenticationType & ControlChars.CrLf)
    .AppendFormat("Is in AppOperators group: {0}", user.IsInRole("MUJTABA03\AppOperators") & ControlChars.CrLf)
    End With

    Call MessageBox.Show(sbDetail.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)

  2. #2
    Join Date
    Oct 2003
    Location
    New York
    Posts
    46

    Re: PROBLEM WITH WindowsPrincipal

    Although this is an old post, not much else posted under WindowsPrincipal. For reference, the documentation under the System.Security.Principal.WindowsPrincipal.IsInRole() method states:


    Note When testing for newly created role information, such as a new user or a new group, it is important to log out and log in to force the propagation of role information within the domain. Not doing so can cause the IsInRole test to return false.
    DaveDaPhoneGuy

    A foolish person doesn't know what he doesn't know and isn't afraid to act on it.
    A lazy person knows what he doesn't know but does nothing about it.
    A wise person knows what he doesn't know and seeks out those that do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured