Detect Remote RDP Session??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim

    #1

    Detect Remote RDP Session??

    Hi Guys,

    I was wondering if there is a way to detect from with a C# app if it is
    being started in a remote session? i.e. someone has connected via remote
    desktop or terminal services...

    Thanks

    Tim


  • Siva M

    #2
    Re: Detect Remote RDP Session??

    I have not tried, but check it: P/Invoke call on GetSystemMetric s(0x1000).
    Should return non-zero under Term. Services. 0, otherwise.

    "Tim" <tim@home.com > wrote in message
    news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
    Hi Guys,

    I was wondering if there is a way to detect from with a C# app if it is
    being started in a remote session? i.e. someone has connected via remote
    desktop or terminal services...

    Thanks

    Tim



    Comment

    • Willy Denoyette [MVP]

      #3
      Re: Detect Remote RDP Session??


      "Tim" <tim@home.com > wrote in message
      news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
      | Hi Guys,
      |
      | I was wondering if there is a way to detect from with a C# app if it is
      | being started in a remote session? i.e. someone has connected via remote
      | desktop or terminal services...
      |
      | Thanks
      |
      | Tim
      |
      |

      Check the Process.Session Id property, if it's non zero it means you are
      running in a TS session.

      Willy.


      Comment

      • Tim

        #4
        Re: Detect Remote RDP Session??

        Thanks for the reply Siva, I don't suppose you could give me some more
        information. I am not sure how to proceed. I would appreciate some actual
        code if you can.

        Thanks

        Tim


        "Siva M" <shiva_sm@onlin e.excite.com> wrote in message
        news:%23xbtbQ6E GHA.272@TK2MSFT NGP10.phx.gbl.. .[color=blue]
        >I have not tried, but check it: P/Invoke call on GetSystemMetric s(0x1000).
        > Should return non-zero under Term. Services. 0, otherwise.
        >
        > "Tim" <tim@home.com > wrote in message
        > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
        > Hi Guys,
        >
        > I was wondering if there is a way to detect from with a C# app if it is
        > being started in a remote session? i.e. someone has connected via remote
        > desktop or terminal services...
        >
        > Thanks
        >
        > Tim
        >
        >
        >[/color]


        Comment

        • Tim

          #5
          Re: Detect Remote RDP Session??

          I think this only works for .Net 2.0. I am using 1.1 still...

          "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
          news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          >
          > "Tim" <tim@home.com > wrote in message
          > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
          > | Hi Guys,
          > |
          > | I was wondering if there is a way to detect from with a C# app if it is
          > | being started in a remote session? i.e. someone has connected via remote
          > | desktop or terminal services...
          > |
          > | Thanks
          > |
          > | Tim
          > |
          > |
          >
          > Check the Process.Session Id property, if it's non zero it means you are
          > running in a TS session.
          >
          > Willy.
          >
          >[/color]


          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Detect Remote RDP Session??

            That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId, something
            like this will do:


            [DllImport("Kern el32")
            extern static int ProcessIdToSess ionId(int procId, out int sessId);

            int procId = Process.getCurr entProcess().Id ;
            int sessId = 0;

            if(ProcessIdToS essionId(procId , out sessId) != 0)
            {
            if (sessId == 0)
            // no TS
            else
            // in TS
            }
            else
            // API call failed

            Willy.



            "Tim" <tim@home.com > wrote in message
            news:YR_vf.4262 1$X25.1270159@n ews20.bellgloba l.com...
            |I think this only works for .Net 2.0. I am using 1.1 still...
            |
            | "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
            | news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..
            | >
            | > "Tim" <tim@home.com > wrote in message
            | > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
            | > | Hi Guys,
            | > |
            | > | I was wondering if there is a way to detect from with a C# app if it
            is
            | > | being started in a remote session? i.e. someone has connected via
            remote
            | > | desktop or terminal services...
            | > |
            | > | Thanks
            | > |
            | > | Tim
            | > |
            | > |
            | >
            | > Check the Process.Session Id property, if it's non zero it means you are
            | > running in a TS session.
            | >
            | > Willy.
            | >
            | >
            |
            |


            Comment

            • Tim

              #7
              Re: Detect Remote RDP Session??

              Hi Wily,

              I tried this

              [DllImport("kern el32.dll")]
              static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
              pSessionId);
              uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
              uint sessId = 0;
              if(ProcessIdToS essionId(procId , out sessId))
              {
              if (sessId == 0)
              {
              // no TS
              }
              else
              {
              // in TS
              }
              }

              but it is 0 for remote logins... Any other ideas??

              Tim

              "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
              news:ez92wgDFGH A.3700@TK2MSFTN GP15.phx.gbl...[color=blue]
              > That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
              > something
              > like this will do:
              >
              >
              > [DllImport("Kern el32")
              > extern static int ProcessIdToSess ionId(int procId, out int sessId);
              >
              > int procId = Process.getCurr entProcess().Id ;
              > int sessId = 0;
              >
              > if(ProcessIdToS essionId(procId , out sessId) != 0)
              > {
              > if (sessId == 0)
              > // no TS
              > else
              > // in TS
              > }
              > else
              > // API call failed
              >
              > Willy.
              >
              >
              >
              > "Tim" <tim@home.com > wrote in message
              > news:YR_vf.4262 1$X25.1270159@n ews20.bellgloba l.com...
              > |I think this only works for .Net 2.0. I am using 1.1 still...
              > |
              > | "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
              > | news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..
              > | >
              > | > "Tim" <tim@home.com > wrote in message
              > | > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
              > | > | Hi Guys,
              > | > |
              > | > | I was wondering if there is a way to detect from with a C# app if it
              > is
              > | > | being started in a remote session? i.e. someone has connected via
              > remote
              > | > | desktop or terminal services...
              > | > |
              > | > | Thanks
              > | > |
              > | > | Tim
              > | > |
              > | > |
              > | >
              > | > Check the Process.Session Id property, if it's non zero it means you
              > are
              > | > running in a TS session.
              > | >
              > | > Willy.
              > | >
              > | >
              > |
              > |
              >
              >[/color]


              Comment

              • Tim

                #8
                Re: Detect Remote RDP Session??

                I think I may have found the problem; the 'server' I am using is a WinXP Pro
                machine... does this mean it will not work? MSDN documentation;
                http://msdn.microsoft.com/library/de...osessionid.asp

                Tim

                "Tim" <tim@home.com > wrote in message
                news:N%awf.125$ W03.34009@news2 0.bellglobal.co m...[color=blue]
                > Hi Wily,
                >
                > I tried this
                >
                > [DllImport("kern el32.dll")]
                > static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
                > pSessionId);
                > uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
                > uint sessId = 0;
                > if(ProcessIdToS essionId(procId , out sessId))
                > {
                > if (sessId == 0)
                > {
                > // no TS
                > }
                > else
                > {
                > // in TS
                > }
                > }
                >
                > but it is 0 for remote logins... Any other ideas??
                >
                > Tim
                >
                > "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                > news:ez92wgDFGH A.3700@TK2MSFTN GP15.phx.gbl...[color=green]
                >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
                >> something
                >> like this will do:
                >>
                >>
                >> [DllImport("Kern el32")
                >> extern static int ProcessIdToSess ionId(int procId, out int sessId);
                >>
                >> int procId = Process.getCurr entProcess().Id ;
                >> int sessId = 0;
                >>
                >> if(ProcessIdToS essionId(procId , out sessId) != 0)
                >> {
                >> if (sessId == 0)
                >> // no TS
                >> else
                >> // in TS
                >> }
                >> else
                >> // API call failed
                >>
                >> Willy.
                >>
                >>
                >>
                >> "Tim" <tim@home.com > wrote in message
                >> news:YR_vf.4262 1$X25.1270159@n ews20.bellgloba l.com...
                >> |I think this only works for .Net 2.0. I am using 1.1 still...
                >> |
                >> | "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                >> | news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..
                >> | >
                >> | > "Tim" <tim@home.com > wrote in message
                >> | > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
                >> | > | Hi Guys,
                >> | > |
                >> | > | I was wondering if there is a way to detect from with a C# app if
                >> it
                >> is
                >> | > | being started in a remote session? i.e. someone has connected via
                >> remote
                >> | > | desktop or terminal services...
                >> | > |
                >> | > | Thanks
                >> | > |
                >> | > | Tim
                >> | > |
                >> | > |
                >> | >
                >> | > Check the Process.Session Id property, if it's non zero it means you
                >> are
                >> | > running in a TS session.
                >> | >
                >> | > Willy.
                >> | >
                >> | >
                >> |
                >> |
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • Willy Denoyette [MVP]

                  #9
                  Re: Detect Remote RDP Session??

                  Windows client OS's don't run real TS sessions, they use TS technology to
                  present a remote desktop session (single session only), guess that's the
                  reason why 0 is returned.

                  Willy.

                  "Tim" <tim@home.com > wrote in message
                  news:K5bwf.129$ W03.34655@news2 0.bellglobal.co m...
                  |I think I may have found the problem; the 'server' I am using is a WinXP
                  Pro
                  | machine... does this mean it will not work? MSDN documentation;
                  |
                  http://msdn.microsoft.com/library/de...osessionid.asp
                  |
                  | Tim
                  |
                  | "Tim" <tim@home.com > wrote in message
                  | news:N%awf.125$ W03.34009@news2 0.bellglobal.co m...
                  | > Hi Wily,
                  | >
                  | > I tried this
                  | >
                  | > [DllImport("kern el32.dll")]
                  | > static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
                  | > pSessionId);
                  | > uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
                  | > uint sessId = 0;
                  | > if(ProcessIdToS essionId(procId , out sessId))
                  | > {
                  | > if (sessId == 0)
                  | > {
                  | > // no TS
                  | > }
                  | > else
                  | > {
                  | > // in TS
                  | > }
                  | > }
                  | >
                  | > but it is 0 for remote logins... Any other ideas??
                  | >
                  | > Tim
                  | >
                  | > "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                  | > news:ez92wgDFGH A.3700@TK2MSFTN GP15.phx.gbl...
                  | >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
                  | >> something
                  | >> like this will do:
                  | >>
                  | >>
                  | >> [DllImport("Kern el32")
                  | >> extern static int ProcessIdToSess ionId(int procId, out int sessId);
                  | >>
                  | >> int procId = Process.getCurr entProcess().Id ;
                  | >> int sessId = 0;
                  | >>
                  | >> if(ProcessIdToS essionId(procId , out sessId) != 0)
                  | >> {
                  | >> if (sessId == 0)
                  | >> // no TS
                  | >> else
                  | >> // in TS
                  | >> }
                  | >> else
                  | >> // API call failed
                  | >>
                  | >> Willy.
                  | >>
                  | >>
                  | >>
                  | >> "Tim" <tim@home.com > wrote in message
                  | >> news:YR_vf.4262 1$X25.1270159@n ews20.bellgloba l.com...
                  | >> |I think this only works for .Net 2.0. I am using 1.1 still...
                  | >> |
                  | >> | "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                  | >> | news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..
                  | >> | >
                  | >> | > "Tim" <tim@home.com > wrote in message
                  | >> | > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
                  | >> | > | Hi Guys,
                  | >> | > |
                  | >> | > | I was wondering if there is a way to detect from with a C# app if
                  | >> it
                  | >> is
                  | >> | > | being started in a remote session? i.e. someone has connected via
                  | >> remote
                  | >> | > | desktop or terminal services...
                  | >> | > |
                  | >> | > | Thanks
                  | >> | > |
                  | >> | > | Tim
                  | >> | > |
                  | >> | > |
                  | >> | >
                  | >> | > Check the Process.Session Id property, if it's non zero it means you
                  | >> are
                  | >> | > running in a TS session.
                  | >> | >
                  | >> | > Willy.
                  | >> | >
                  | >> | >
                  | >> |
                  | >> |
                  | >>
                  | >>
                  | >
                  | >
                  |
                  |


                  Comment

                  • Tim

                    #10
                    Re: Detect Remote RDP Session??

                    Hi Willy (sorry for mis-spelling your name before),

                    Is there any way to tell if it is a remote desktop session that is running
                    on an XP machine or something that is not a server with a proper terminal
                    services session?

                    Tim


                    "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                    news:%23BUiPLJF GHA.3892@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                    > Windows client OS's don't run real TS sessions, they use TS technology to
                    > present a remote desktop session (single session only), guess that's the
                    > reason why 0 is returned.
                    >
                    > Willy.
                    >
                    > "Tim" <tim@home.com > wrote in message
                    > news:K5bwf.129$ W03.34655@news2 0.bellglobal.co m...
                    > |I think I may have found the problem; the 'server' I am using is a WinXP
                    > Pro
                    > | machine... does this mean it will not work? MSDN documentation;
                    > |
                    > http://msdn.microsoft.com/library/de...osessionid.asp
                    > |
                    > | Tim
                    > |
                    > | "Tim" <tim@home.com > wrote in message
                    > | news:N%awf.125$ W03.34009@news2 0.bellglobal.co m...
                    > | > Hi Wily,
                    > | >
                    > | > I tried this
                    > | >
                    > | > [DllImport("kern el32.dll")]
                    > | > static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
                    > | > pSessionId);
                    > | > uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
                    > | > uint sessId = 0;
                    > | > if(ProcessIdToS essionId(procId , out sessId))
                    > | > {
                    > | > if (sessId == 0)
                    > | > {
                    > | > // no TS
                    > | > }
                    > | > else
                    > | > {
                    > | > // in TS
                    > | > }
                    > | > }
                    > | >
                    > | > but it is 0 for remote logins... Any other ideas??
                    > | >
                    > | > Tim
                    > | >
                    > | > "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                    > | > news:ez92wgDFGH A.3700@TK2MSFTN GP15.phx.gbl...
                    > | >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
                    > | >> something
                    > | >> like this will do:
                    > | >>
                    > | >>
                    > | >> [DllImport("Kern el32")
                    > | >> extern static int ProcessIdToSess ionId(int procId, out int sessId);
                    > | >>
                    > | >> int procId = Process.getCurr entProcess().Id ;
                    > | >> int sessId = 0;
                    > | >>
                    > | >> if(ProcessIdToS essionId(procId , out sessId) != 0)
                    > | >> {
                    > | >> if (sessId == 0)
                    > | >> // no TS
                    > | >> else
                    > | >> // in TS
                    > | >> }
                    > | >> else
                    > | >> // API call failed
                    > | >>
                    > | >> Willy.
                    > | >>
                    > | >>
                    > | >>
                    > | >> "Tim" <tim@home.com > wrote in message
                    > | >> news:YR_vf.4262 1$X25.1270159@n ews20.bellgloba l.com...
                    > | >> |I think this only works for .Net 2.0. I am using 1.1 still...
                    > | >> |
                    > | >> | "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in
                    > message
                    > | >> | news:%23BVzXS6E GHA.1464@TK2MSF TNGP11.phx.gbl. ..
                    > | >> | >
                    > | >> | > "Tim" <tim@home.com > wrote in message
                    > | >> | > news:_YQvf.4206 4$X25.1192726@n ews20.bellgloba l.com...
                    > | >> | > | Hi Guys,
                    > | >> | > |
                    > | >> | > | I was wondering if there is a way to detect from with a C# app
                    > if
                    > | >> it
                    > | >> is
                    > | >> | > | being started in a remote session? i.e. someone has connected
                    > via
                    > | >> remote
                    > | >> | > | desktop or terminal services...
                    > | >> | > |
                    > | >> | > | Thanks
                    > | >> | > |
                    > | >> | > | Tim
                    > | >> | > |
                    > | >> | > |
                    > | >> | >
                    > | >> | > Check the Process.Session Id property, if it's non zero it means
                    > you
                    > | >> are
                    > | >> | > running in a TS session.
                    > | >> | >
                    > | >> | > Willy.
                    > | >> | >
                    > | >> | >
                    > | >> |
                    > | >> |
                    > | >>
                    > | >>
                    > | >
                    > | >
                    > |
                    > |
                    >
                    >[/color]


                    Comment

                    Working...