开发者

How do you use LsaEnumerateLogonSessions in C#?

In a C# Windows Forms Application, I'm trying to get a list of the users currently logged into a workstation (both local and domain users). Every search about this has led me to threads mentioning "just use LsaEnumerateLogonSessions".

So...how do you actually use this? The MSDN page is very sparse and doesn't seem to offer 开发者_Python百科any clues.


This article shows how to use LsaEnumerateLogonSessons:
http://www.codeproject.com/Articles/18179/Using-the-Local-Security-Authority-to-Enumerate-Us


You should use Cassia, an open source wrapper.

ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetRemoteServer("your-server-name"))
{
    server.Open();
    foreach (ITerminalServicesSession session in server.GetSessions())
    {
        Console.WriteLine("Session ID: " + session.SessionId);
        Console.WriteLine("User: " + session.UserAccount);
        Console.WriteLine("State: " + session.ConnectionState);
        Console.WriteLine("Logon Time: " + session.LoginTime);
    }
}

I'm not sure how this will handle domain users; try it in LINQPad.

To answer your question, you need to declare it as a P/Invoke method that takes an out in and an out long[].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜