开发者

Terminal Services commands available in a .NET namespace?

Are there .NET equivalent commands to termina开发者_JAVA技巧l services commands 'QWINSTA', 'RWINSTA', AND 'TSDISCON'?

Thanks


Currently there is no .NET / managed API equivalent. You can probably use the functions in wtsapi32.dll though. Check out pinvoke.net for some examples of how to invoke these from managed code... starting with the following:

WTSEnumerateSessions

WTSQuerySessionInformation

WTSLogoffSession

Or, if you don't want to roll your own Win32 wrapper, check out the "cassia" project. I have not used it and therefore cannot vouch for the quality of this solution, however it seems to be a .NET library used for accessing the native Windows Terminal Services API.

The following is an example of how you would use the cassia library in C# (taken from the project site):

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);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜