473,659 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect session start and stop?

My program needs to do X when someone 'starts using' their Windows user
account, and it should do Y when they 'stop using' their Windows user
account. By 'starts using' I mean they log on, unlock the desktop, resume
from hibernate/sleep, or resume a session that was paused via Switch User. By
'stop using' I mean they lock the desktop, initiate a hibernate/sleep
, or choose Switch User while logged on. For context, the program is a
parental control application that helps parents limit the total time their
kids use the computer. There is a Windows service that does the actual time
keeping. The program I'm struggling with is the reminder program that gives
the child audible reminders like "5 minutes left". It should tell them how
much time is left when they start using Windows, and it should be quiet when
they take a break.

This sounds like a simple task, but I can't get it to work reliably.

My current approach is to put the program in the child's StartUp folder.
When the application starts, it does X. It then listens to the events from
SystemEvents.Se ssionSwitch and SystemEvents.Po werModeChanged and does X if it
detects a start event like Unlock and does Y if it detects a stop event like
Suspend.

The first problem is that if you log on and then immediately Lock the
computer or do a Switch User, then by the time my application has fully
loaded it may be running in the context of a locked workstation. So it
shouldn't automatically do X (tell the child how much time is left) when the
application starts. Somehow my program needs to know if it is running in the
context of a locked or switched out Windows session. I don't know how to
check for that.

The second problem is that interpreting the SystemEvents.Se ssionSwitch and
SystemEvents.Po werModeChanged events is tricky. For example, if Windows is
configured to require a password after resuming from sleep, then doing a
hibernate followed by resume leads to these events:
Suspend->Lock->Resume->Unlock. But if Windows is not configured to require a
password after resuming from sleep, then these events are generated:
Suspend->Resume. Therefore I can't simply look to the Resume event to tell me
if the user has started using Windows again. Likewise if you do a Switch user
and then resume, these events are generated: Disconnect->Connect. But if you
do a lock, switch out, switch in, these events are generated:
Lock->Disconnect->Connect->Unlock. Therefore I can't simply look to the
Connect event to tell me if the user has started using Windows again.

Here's my algorithm:

I initialize a variable called "Depth" to 0.
Lock, Disconnect, Suspend all decrement "Depth" by 1.
Unlock, Connect, Resume all increment "Depth" by 1.
When "Depth" changes to 0, that means the user has started using Windows.
When "Depth" changes to -1, that means the user has stopped using Windows.

This works most of the time but if the users session is switched out soon
after they log on and before my application has fully loaded and subscribed
to the events, then "Depth" should not really be initialized to 0. It should
start at -1 or -2. And since I can't properly detect the initial state, I
can't properly interpret all future SessionSwitch and PowerModeChange d events.

How can I reliably do X when someone starts using Windows, and do Y when
they stop?
How can I know whether my program is running in the context of a locked or
switched out user session?
Sep 12 '08 #1
0 3276

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7780
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
15
3584
by: Manish Jethani | last post by:
Hi all, Is there a way to detect typos in a Python program, before actually having to run it. Let's say I have a function like this: def server_closed_connection(): session.abost() Here, abort() is actually misspelt. The only time my program follows this path is when the server disconnects from its
0
1357
by: Cédric | last post by:
Hi, I have some problems to detect when a file is changed by another application (the file is changed several times by the application). Sometimes, it is correctly detected, sometimes not. I maybe expect an access problem. Can it be? And how to solve it? Below is a part of my code (written in C#). Is there anybody who can help me? .... FileSystemWatcher watcher = new FileSystemWatcher();
4
5802
by: sanjana | last post by:
hi can anyone help me with this i want to write a code in c#.net which detects usb storage and media card insertion can anyone help me with this?? thanx
4
1512
by: Chad | last post by:
I rebuilt my pc (format and reinstall) running XP and Visual Studio 2003. My problem is that the IDE won't stop the run session when I close the web application. Now when I create a new ASP.net application or open an existing application, start the application (F5) in the IDE, close the IE window that the application started up, now you would expect the IDE to also stop it's debug session ie; run mode. However mine is not, the IDE is
4
1894
by: Harri Pesonen | last post by:
I have an ASP.NET application that runs threads in background. Application does not close if the web site is stopped. So how can the application get an event when the site has been stopped, so that it could shutdown itself? Application already closes itself gracefully if Application_Disposed is called, but this is not called in this case. Thanks, Harri
2
9257
by: Cam | last post by:
Hi to all I have searched this subject and found some posts but none of them seem to answer my problem. I am developing a shop site and need to detect when a session times out through inactivity and tell the user that it has been reset and he has to start over. I set some session variables in a global.asa file so when the user restarts
5
1678
by: Terry On Windigo | last post by:
I think I have figured out my problem but I don't know how to solve it. We are going to start using a forums package and do not want our users to have to login to both our site, and then again to the forums package. The creator of the forums package provides what seems to be an easy workaround for this. Create two session variables, one for ID, the other for Password, and his program will take care of the rest. I have all of my forums...
5
2569
by: jediknight | last post by:
Is it possible to programmatically stop multiple browsers from getting the same session state? The problem I have is that whenever I open a new browse using File- I would like to stop this from happening and redirect to the homepage. Thanks in advance!
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.