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 / C++ / MFC
  4. Need help detecting switching users

Need help detecting switching users

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 5 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.
  • D Offline
    D Offline
    DeepT
    wrote on last edited by
    #1

    I have an application I am writting that needs to run for any user logged on. The problem lies in the fact that if User1 switches out (not logs out), and then user2 logs in, another instance of my application runs, which is ok, except the compete with each other. What I want to happen is to be able to tell if the user the program is running under is no longer the active user, then my program can sleep until it becomes the active user again. IE: User1 longs in, starts instance 1, and switches out. User2 logs in, starts instance 2. Instance 1 knows its no longer active and goes to sleep. User2 eventually switches out, and user1 comes back. Instance2 goes to sleep, and instance 1 wakes up. Any ideas?

    S M S 3 Replies Last reply
    0
    • D DeepT

      I have an application I am writting that needs to run for any user logged on. The problem lies in the fact that if User1 switches out (not logs out), and then user2 logs in, another instance of my application runs, which is ok, except the compete with each other. What I want to happen is to be able to tell if the user the program is running under is no longer the active user, then my program can sleep until it becomes the active user again. IE: User1 longs in, starts instance 1, and switches out. User2 logs in, starts instance 2. Instance 1 knows its no longer active and goes to sleep. User2 eventually switches out, and user1 comes back. Instance2 goes to sleep, and instance 1 wakes up. Any ideas?

      S Offline
      S Offline
      SandeepN
      wrote on last edited by
      #2

      Are you running your application on Windows Terminal Services also ? i.e. Two users can concurrently login Sandeep Naik

      D 1 Reply Last reply
      0
      • S SandeepN

        Are you running your application on Windows Terminal Services also ? i.e. Two users can concurrently login Sandeep Naik

        D Offline
        D Offline
        DeepT
        wrote on last edited by
        #3

        I suppose so. Its standard windows XP, both pro and home can do this. I understand all NT kernal OSs can do it as well although its not as easy to do as it is under windows XP.

        B 1 Reply Last reply
        0
        • D DeepT

          I suppose so. Its standard windows XP, both pro and home can do this. I understand all NT kernal OSs can do it as well although its not as easy to do as it is under windows XP.

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          Process this winbdow message your application: WM_WTSSESSION_CHANGE The WM_WTSSESSION_CHANGE message notifies applications of changes in session state. The window receives this message through its WindowProc function. See also: WTSRegisterSessionNotification The WTSRegisterSessionNotification function registers the specified window to receive session change notifications.

          1 Reply Last reply
          0
          • D DeepT

            I have an application I am writting that needs to run for any user logged on. The problem lies in the fact that if User1 switches out (not logs out), and then user2 logs in, another instance of my application runs, which is ok, except the compete with each other. What I want to happen is to be able to tell if the user the program is running under is no longer the active user, then my program can sleep until it becomes the active user again. IE: User1 longs in, starts instance 1, and switches out. User2 logs in, starts instance 2. Instance 1 knows its no longer active and goes to sleep. User2 eventually switches out, and user1 comes back. Instance2 goes to sleep, and instance 1 wakes up. Any ideas?

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            You can use the standard single instance checking mechanisms (like a mutex) but prefix the mutex name with "Global\" to make it visible in all terminal services sessions. That way your code can tell if another instance of the app is running in any session. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "die" ahhhh! "diet" AAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!

            1 Reply Last reply
            0
            • D DeepT

              I have an application I am writting that needs to run for any user logged on. The problem lies in the fact that if User1 switches out (not logs out), and then user2 logs in, another instance of my application runs, which is ok, except the compete with each other. What I want to happen is to be able to tell if the user the program is running under is no longer the active user, then my program can sleep until it becomes the active user again. IE: User1 longs in, starts instance 1, and switches out. User2 logs in, starts instance 2. Instance 1 knows its no longer active and goes to sleep. User2 eventually switches out, and user1 comes back. Instance2 goes to sleep, and instance 1 wakes up. Any ideas?

              S Offline
              S Offline
              shaileshkumar
              wrote on last edited by
              #6

              Well there are multiple ways to acheive this functionality: 1) Use registry entries under HKLM, which is common for all users logged on to convey any message between different users. 2) I assume that both your program are using/modifying some common files, that is the reason, you are having problems, in that case, you can think of using semaphores to lock the files. Don't know if this would solve the problem :) Well to add to your problem, a doubt i have, is if you are using Windows XP, it supports only one session, so if user1 have switched out and user2 wants to logon, when user2 logs on, XP switches out user1. Are you sure this is not applicable to you? - Shailesh

              D 1 Reply Last reply
              0
              • S shaileshkumar

                Well there are multiple ways to acheive this functionality: 1) Use registry entries under HKLM, which is common for all users logged on to convey any message between different users. 2) I assume that both your program are using/modifying some common files, that is the reason, you are having problems, in that case, you can think of using semaphores to lock the files. Don't know if this would solve the problem :) Well to add to your problem, a doubt i have, is if you are using Windows XP, it supports only one session, so if user1 have switched out and user2 wants to logon, when user2 logs on, XP switches out user1. Are you sure this is not applicable to you? - Shailesh

                D Offline
                D Offline
                DeepT
                wrote on last edited by
                #7

                Well to answer these 3 replies.. 1. I am not using a 'windowed' application, so I do not have any windows message loop, and therefor I can not look for a switch session message, although now that I know its called a 'session' I may be able to find more help. However I am unsure exactly what you mean by sessions here, so it may be a red herring for me. 2. Just finding out if another instance of my program is running does not help me. I need to find *which* is the one that belongs to the currently active user. 3. My program is talking to a server and it monitors the local users machine. The problem is two fold. For one machine the server will get two reports (or more, one for each user logged in) from the same box. The second problem is the server tells my program to give the user some information, such as they do not have any anti-virus software running. The problem is, if user1 and user2 are logged in, with user2 as the active user, the user1 instance may pick up the message and user2 will never see it. So what I need is to figure out if *this* instance is the active user instance. If the answer is no, I go to sleep until it is. Otherwise I operate normally. So it doesn't really come down to having only one instance of my program running or any interprocess communicatiion. I just need to tell if *this* user is the active one, and so far, I can not find a way to do that.

                D 1 Reply Last reply
                0
                • D DeepT

                  Well to answer these 3 replies.. 1. I am not using a 'windowed' application, so I do not have any windows message loop, and therefor I can not look for a switch session message, although now that I know its called a 'session' I may be able to find more help. However I am unsure exactly what you mean by sessions here, so it may be a red herring for me. 2. Just finding out if another instance of my program is running does not help me. I need to find *which* is the one that belongs to the currently active user. 3. My program is talking to a server and it monitors the local users machine. The problem is two fold. For one machine the server will get two reports (or more, one for each user logged in) from the same box. The second problem is the server tells my program to give the user some information, such as they do not have any anti-virus software running. The problem is, if user1 and user2 are logged in, with user2 as the active user, the user1 instance may pick up the message and user2 will never see it. So what I need is to figure out if *this* instance is the active user instance. If the answer is no, I go to sleep until it is. Otherwise I operate normally. So it doesn't really come down to having only one instance of my program running or any interprocess communicatiion. I just need to tell if *this* user is the active one, and so far, I can not find a way to do that.

                  D Offline
                  D Offline
                  DeepT
                  wrote on last edited by
                  #8

                  I was looking at task manager and a bunch of things are running as 'SYSTEM'. If I switch users, they are still running with no duplicates. I am thinking I can run my app as user system it will solve my problem. However, I do not know how to do this. Also, are there any restrictions a process running under user system have? Can something running under user system still pop message boxes and web pages that will be visible to all users? Thanks, --DeepT

                  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