Getting the NT groups from TSQL

  • Hi!

    I'm trying to get the NT group membership of a specified username from TSQL. I'm using the following to query the OS:

    SELECT *

    FROM OPENROWSET(NetUserGetGroups, @NTUserName) AS NT

    It works fine except the fact that it seems that the result is cached somewhere, because if I run it once when a user is member of a certain group it, and then remove the user from the group and rerun the statement, it still reports the user as a group member. Even if I remove the group altogether, it still lists the group.

    Any tips on this or alternative strategies?

    Brgds

    Jonas

    BrgdsJonas

  • have a look at IS_MEMBER


    * Noel

  • Hi!

    Unfortunately IS_MEMBER does not work for me as I have to be able to specify a username different from current user and check membership for it.

    Thanks anyway

    Jonas

    BrgdsJonas

  • How about:

     
    
    exec master..xp_logininfo N'DomainName\Group', N'members'

    Note: The Group Have to Have Access To SQL Server though


    * Noel

  • Sorry, I should have stated in my original question that I'm using a single account to access the SQL Server from a COM+ application, so the users I want to check NT group memberships for isn't users in SQL Server, only in the NT domain/local computer.

    Brgds

    Jonas

    BrgdsJonas

  • Some more investigations has revealed that the time for a group membership change to appear when using this function is between a couple of minutes up to almost ten minutes.

    /Jonas

    BrgdsJonas

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply