Can JavaScript detect when the PC is locked or the screensaver activates?

I'm writing an application at the moment - an alert system for the company website, in the form of a popup window that sits in the background, updating every few seconds and tells the user if a new alert is generated. What I would like to do is somehow detect when the user locks their screen or the screensaver appears (idle timeout of 20 minutes).

Basically alerts would appear in this popup window, but if the users locks their screen or the screensaver appears, we want to re-route alerts to email instead, as staff have Windows Mobile devices.

Does anyone know if any of this is possible? Could JavaScript do this, or jQuery, or would I have to use something else?

We're using Windows XP SP3 site-wide and IE7 only.

Any help appreciated.

Thanks in advance.
DReade83Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
The short answer is: no, you cannot do that.
The longer answer is: you cannot do that because javascript does not have any rights on the underlying system, the same way you can never save a file without user interaction on a client's machine, or change his clock or security settings.

The even longer answer is: you can do that, but then you need to write your own plugin for Firefox, Opera, Safari, Chrome and an Add-On or ActiveX control for Internet Explorer. You'll then have to instruct your users to install this plugin and from then on, you can access just about everything you want. But the question then is: would you users trust you well enough to allow installation of a plugin that potentially harms their computer or opens a security hole? I can't judge that for you, but because you say that you only have to code for IE7 and Windows-based systems, you may just stick with ActiveX or Browser Extensions (not sure if extensions can do this, or even an ActiveX, they still operate under the security of the browser) or an Add-On.

It will cost significant time to write something like that. Sorry that I don't have better news for you.

-- Abel --
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BadotzCommented:
If the client can poll a process on the server (using Ajax) that in turn checks for the screensaver being active (can anything do that?) then I see no reason why such a scenario would not work for you.

It would take some development, to be sure, but then, what doesn't?

Or am I missing something impossible here?
0
DReade83Author Commented:
OK, what about Flex or Flash? Isn't that classed as a client-side application? Could that do the same thing as ActiveX?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

BadotzCommented:
Ah, it's all about the client. Sorry for my lizard-brain idea...Ajax will be of no use here...
0
abelCommented:
No, Flex of Flash are designed as general purpose plugins. Yes, they can do more then HTML + JS. No, they cannot access your system in any way. A flash, silverlight or flex application must run in the browser context. No user would install or trust Flash anymore if any malicious user building a website could access any information on the computer outside the browser context.

Flash can run standalone and it can have an elavated privilege, just as javascript can have an elavated privilege. The user gets a security warning, something along the lines "do you trust this page to allow it to access security sensitive data on your system? Click yes or no".

But, just accessing something on the system is one thing. Monitoring a system in realtime and asynchronously sending that data back is another thing (HTTP is stateless and never meant for keeping connections alive, it is not even possible, but with some tricks, like with AJAX, you can simulate that behavior).

-- Abel --
0
DReade83Author Commented:
Ah well, thanks man for your help, highly appreciated!
0
abelCommented:
You're welcome, glad you appreciate it (most askers hate it when you have to tell them bad news or "it can't be done").
0
ChrisDrakeCommented:
These answers all sound wrong.
Your app runs on PCs, so can be written as a hypertext application (.HTA) - which can use VBScript instead of JavaScript, which *can* detect the screensaver in a number of different ways.

See http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24300306.html
0
abelCommented:
HTA does not have this power when served in a web page, unless the user explicitly grands it. Otherwise, visiting a certain web page with HTA would open up your system to anyone who wants. Though it is a tempting idea. But if you serve HTA you can also serve any of the other suggestions.

Why would "all these answers" be wrong? You can always write a plugin. No, you cannot access the system without user consent from a web page, HTA or otherwise and no, you cannot access your system with a flash or flex script.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.