Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. get current session ID

get current session ID

Scheduled Pinned Locked Moved C#
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crash893
    wrote on last edited by
    #1

    Hi all Where would i look to get the session ID of the program I made I can find the session ID or other process's and i want to compare them to the session ID of my program to make sure its okay to kill them and not accidentally kill a process on another session.

    T 1 Reply Last reply
    0
    • C crash893

      Hi all Where would i look to get the session ID of the program I made I can find the session ID or other process's and i want to compare them to the session ID of my program to make sure its okay to kill them and not accidentally kill a process on another session.

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessesByName("devenv");
      p.SessionId; //if you want sessionid
      p.Id; //if you want PID

      C 1 Reply Last reply
      0
      • T Tarakeshwar Reddy

        System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessesByName("devenv");
        p.SessionId; //if you want sessionid
        p.Id; //if you want PID

        C Offline
        C Offline
        crash893
        wrote on last edited by
        #3

        will that work? lets say i have 10 people logged on and they are all running the same program (windowsapplicaiton3.exe) for example wont it return p.sessionID for all 10 people? i guess what im asking is how does my program know its own session state?

        G T 2 Replies Last reply
        0
        • C crash893

          will that work? lets say i have 10 people logged on and they are all running the same program (windowsapplicaiton3.exe) for example wont it return p.sessionID for all 10 people? i guess what im asking is how does my program know its own session state?

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          Why don't you give it a try?

          my articles

          C 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            Why don't you give it a try?

            my articles

            C Offline
            C Offline
            crash893
            wrote on last edited by
            #5

            sure which one?

            C 1 Reply Last reply
            0
            • C crash893

              sure which one?

              C Offline
              C Offline
              crash893
              wrote on last edited by
              #6

              i also found this [DllImport("kernel32.dll")] static extern bool ProcessIdToSessionId(uint dwProcessId, out uint pSessionId); static void Main(string[] args) { Process _currentProcess = Process.GetCurrentProcess(); uint _processID = (uint)_currentProcess.Id; uint _sessionID; bool _result = ProcessIdToSessionId(_processID, out _sessionID); Console.WriteLine("ProcessIdToSessionId Result: " + _result.ToString()); Console.WriteLine("Process ID = " + _processID.ToString()); Console.WriteLine("Session ID = " + _sessionID.ToString()); Console.ReadLine(); } but im unclear on how to implement it im still a little green with .net

              1 Reply Last reply
              0
              • C crash893

                will that work? lets say i have 10 people logged on and they are all running the same program (windowsapplicaiton3.exe) for example wont it return p.sessionID for all 10 people? i guess what im asking is how does my program know its own session state?

                T Offline
                T Offline
                Tarakeshwar Reddy
                wrote on last edited by
                #7

                You can get the session if of your application using System.Diagnostics.Process.GetCurrentProcess().SessionId; and System.Diagnostics.Process.GetCurrentProcess().Id; Using the PID of your current process, you can kill your process.

                C 1 Reply Last reply
                0
                • T Tarakeshwar Reddy

                  You can get the session if of your application using System.Diagnostics.Process.GetCurrentProcess().SessionId; and System.Diagnostics.Process.GetCurrentProcess().Id; Using the PID of your current process, you can kill your process.

                  C Offline
                  C Offline
                  crash893
                  wrote on last edited by
                  #8

                  thats it thanks

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups