Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4087342
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:50:35+00:00 2026-05-20T18:50:35+00:00

I need to get the underlying client PC name from a user’s terminal server

  • 0

I need to get the underlying client PC name from a user’s terminal server session.

I know it lives in HKEY_CURRENT_USER\Volatile Environment\CLIENTNAME but is there another (preferably native .net) method of getting it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:50:36+00:00Added an answer on May 20, 2026 at 6:50 pm

    I didn’t see a managed API for this. The only API-based ways I could see for getting at this information would be through WMI or the native Terminal Services API in Windows.

    Here is an example that returns the client name using the WTSQuerySessionInformation API:

    namespace com.stackoverflow
    {
        using System;
        using System.Runtime.InteropServices;
    
        public class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(GetTerminalServicesClientName());
            }
    
            /// <summary>
            /// Gets the name of the client system.
            /// </summary>
            internal static string GetTerminalServicesClientName()
            {
                IntPtr buffer = IntPtr.Zero;
    
                string clientName = null;
                int bytesReturned;
    
                bool success = NativeMethods.WTSQuerySessionInformation(
                    NativeMethods.WTS_CURRENT_SERVER_HANDLE,
                    NativeMethods.WTS_CURRENT_SESSION,
                    NativeMethods.WTS_INFO_CLASS.WTSClientName,
                    out buffer,
                    out bytesReturned);
    
                if (success)
                {
                    clientName = Marshal.PtrToStringUni(
                        buffer,
                        bytesReturned / 2 /* Because the DllImport uses CharSet.Unicode */
                        );
                    NativeMethods.WTSFreeMemory(buffer);
                }
    
                return clientName;
            }
        }
    
        public static class NativeMethods
        {
            public static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
            public const int WTS_CURRENT_SESSION = -1;
    
            public enum WTS_INFO_CLASS
            {
                WTSClientName = 10
            }
    
            [DllImport("Wtsapi32.dll", CharSet = CharSet.Unicode)]
            public static extern bool WTSQuerySessionInformation(
                IntPtr hServer,
                Int32 sessionId,
                WTS_INFO_CLASS wtsInfoClass,
                out IntPtr ppBuffer,
                out Int32 pBytesReturned);
    
            /// <summary>
            /// The WTSFreeMemory function frees memory allocated by a Terminal
            /// Services function.
            /// </summary>
            /// <param name="memory">Pointer to the memory to free.</param>
            [DllImport("wtsapi32.dll", ExactSpelling = true, SetLastError = false)]
            public static extern void WTSFreeMemory(IntPtr memory);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a log of user access to our SQL Server so
I need to get the default printer name. I'll be using C# but I
I need to get the name of the machine my .NET app is running
How can I get the underlying DataItem from a GridView row that is in
Here's an interesting request. A client will need to blog from the north pole.
I have a GridView. At event _RowDataBound I need take the underlying value from
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I'm working with C#.net developing applications for windows mobile 6, and i need get
I have two tables with a weak relation. I need get a text value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.