none
How to determine whether a program is executed from Local or Remote session(such as mstsc) RRS feed

  • 問題

  • There is a program test.exe , I will run it on PC1 in two following ways:

    1. login in to PC1, and run it locally.

    2. use mstsc to connect to PC1, and run it.

    How to distinuingsh between this two ways in test.exe?? Thanks.

    2013年2月1日 上午 09:09

解答

  • Thanks, it seems GetSystemMetrics can not do this.l

    I finally use this

        std::wstring GetSessionClientProtocolType()
        {
            std::wstring szRet = L"";
            LPTSTR pBuffer = NULL;
            DWORD dwByteRead;
            if (WTSQuerySessionInformation(
                WTS_CURRENT_SERVER_HANDLE,
                WTS_CURRENT_SESSION,
                WTSClientProtocolType,
                &pBuffer,
                &dwByteRead
                ))
            {
                USHORT sProtocolType = *(USHORT *)pBuffer;
                switch (sProtocolType){
                case WTS_PROTOCOL_TYPE_CONSOLE:
                    szRet = SESSION_TYPE_CONSOLE;
                    break;
                case WTS_PROTOCOL_TYPE_RDP:
                    szRet = SESSION_TYPE_RDP;
                    break;
                }
    
                WTSFreeMemory(pBuffer);
            }
    
            return szRet;
        }

    • 已標示為解答 Andyzn 2013年3月16日 上午 08:43
    2013年3月16日 上午 08:43

所有回覆

  • Hi,

    Reference it...

    GetSystemMetrics function (Windows)

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx


    謙卑學習,持之以恆,才能不斷的Level Up http://www.dotblogs.com.tw/larrynung/

    2013年2月1日 上午 10:12
  • If test.exe is a win32 application, then the application run with permission under the login account
    2013年2月1日 下午 02:00
  • Thanks, it seems GetSystemMetrics can not do this.l

    I finally use this

        std::wstring GetSessionClientProtocolType()
        {
            std::wstring szRet = L"";
            LPTSTR pBuffer = NULL;
            DWORD dwByteRead;
            if (WTSQuerySessionInformation(
                WTS_CURRENT_SERVER_HANDLE,
                WTS_CURRENT_SESSION,
                WTSClientProtocolType,
                &pBuffer,
                &dwByteRead
                ))
            {
                USHORT sProtocolType = *(USHORT *)pBuffer;
                switch (sProtocolType){
                case WTS_PROTOCOL_TYPE_CONSOLE:
                    szRet = SESSION_TYPE_CONSOLE;
                    break;
                case WTS_PROTOCOL_TYPE_RDP:
                    szRet = SESSION_TYPE_RDP;
                    break;
                }
    
                WTSFreeMemory(pBuffer);
            }
    
            return szRet;
        }

    • 已標示為解答 Andyzn 2013年3月16日 上午 08:43
    2013年3月16日 上午 08:43
  • Hi,

    It's work...


    謙卑學習,持之以恆,才能不斷的Level Up http://www.dotblogs.com.tw/larrynung/

    2013年3月18日 上午 02:27