Getting users domain name

  • Is it possible to get the windows domain name for all users in a database? The sysusers table holds only the sql user name. Can I somehow use the SID to get the LAN name?

  • Check the logins with

    SELECT name

    FROM master.dbo.syslogins

    WHERE IsNTName = 1

  • Thanks, but the name could be anything I type in when adding the user and is not the actual windows login name.  I need the latter....

  • Good morning folks,

    Maybe someone will have an idea for me today!

    For example, could I somehow use the SID in the sysusers table to find out the domain name (without using OA_ procedures)?

    TIA

  • Hi,

    Maybe using suser_sname(), and formatting result:

    select 

            name as sql_user,

            suser_sname(sid) as login,

            left( suser_sname(sid), charindex('\', suser_sname(sid))-1 ) as domain,

            substring( suser_sname(sid), charindex('\', suser_sname(sid))+1, len(suser_sname(sid)) ) as domain_user,

            sid

    from

            sysusers

    where

            isntuser = 1

     

    //rockmoose


    You must unlearn what You have learnt

  • Perfect - exactly what I need. Thanks!

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

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