2

I have a remote machine and I want to get all logged in user details. I wrote the code using cassia as follwoign using this link

    ITerminalServicesManager manager = new TerminalServicesManager();
    using (ITerminalServer server = manager.GetRemoteServer("SERVERIPADDRESS"))
    {
        server.Open();
        foreach (ITerminalServicesSession session in server.GetSessions())
        {
            NTAccount account = session.UserAccount;
            string userName = session.UserName;

            if (account != null)
            {
                Console.WriteLine(account);
            }
        }
    }

Now I want to connect to this server using a particular UserId and Password. How can I do it? I am not getting any option for that.

What I tried is, I gave the server ip address and build the solution. Then I tried the exe file as a different user and giving credentials but failed to login.

Can anyone please help. I am ready and open to ditch Cassia, but want a working solution.

And please help me tagging this question, I cant get my mind around it.

Community
  • 1
  • 1
Sandy
  • 11,332
  • 27
  • 76
  • 122

2 Answers2

3

As Dan Ports had mentioned, impersonation is definitely the way to go.

If, after using impersonation, you're still unable to connect, I found that non-server OSes (ex. Windows 7 or Windows 8.1) need a registry edit at the following location to make Cassia requests work:

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TerminalServer

At this location, change the value of AllowRemoteRPC to 1.

A N
  • 276
  • 5
  • 18
1

You'll need to use impersonation -- the underlying Remote Desktop Services API does not support passing in credentials as parameters. See Cassia issue 32 and the links in the comments there for more information on impersonation.

Dan Ports
  • 1,421
  • 9
  • 7