Get SID from user

19 views
Skip to first unread message

Patrick Ma

unread,
Jun 30, 2015, 9:05:43 PM6/30/15
to cassia...@googlegroups.com
Hi community,

I love to use cassia and in my case I write an application for terminalserver.
It is very easy to get userinformation (with ITerminalServicesSession objects) - but how do I get the SID from this ITerminalServicesSession object / user?

Thanks,
Patrick

Robert Gijsen

unread,
Jul 1, 2015, 7:34:56 AM7/1/15
to cassia...@googlegroups.com
You can't as the Cassia SessionID does not hold the SID as a property. I use the following, using System.DirectoryServices.AccountManagement. I use VB.NET but this could simply be used in any other .net language.

Imports System.DirectoryServices.AccountManagement
Imports CassiaDim Domain As 

<define class here>

Dim Domain As String = "CONTOSO"
Dim DomainDN As String = "DC=contoso,DC=com"
Dim DomainContext As New PrincipalContext(ContextType.Domain, Domain, DomainDN)

Dim TSServer As ITerminalServer
Dim TSManager As New TerminalServicesManager()
TSServer = TSManager.GetLocalServer()

For Each Session As ITerminalServicesSession In TSServer.GetSessions
   Console.WriteLine("Sid: " & UserPrincipal.FindByIdentity(DomainContext, IdentityType.SamAccountName, Session.UserName).Sid.ToString)
Next




--
You received this message because you are subscribed to the Google Groups "Cassia Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cassia-users...@googlegroups.com.
To post to this group, send email to cassia...@googlegroups.com.
Visit this group at http://groups.google.com/group/cassia-users.
For more options, visit https://groups.google.com/d/optout.

Patrick Ma

unread,
Jul 5, 2015, 5:18:20 AM7/5/15
to cassia...@googlegroups.com
thanks for input @ Robert Gijsen. 

I solved this with this code: 

public String GetSID(ITerminalServicesSession UserSession)
        {
            NTAccount NTAccountUser = new NTAccount(UserSession.UserName);
            SecurityIdentifier SID = (SecurityIdentifier)NTAccountUser.Translate(typeof(SecurityIdentifier));
            String SIDString = SID.ToString();
            return SIDString;
        }

Maybe it is not perfect. but it works. thanks. 
Reply all
Reply to author
Forward
0 new messages