Solved

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

Posted on 2009-07-03
9
1,345 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:DReade83
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24774754
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
 
LVL 29

Expert Comment

by:Badotz
ID: 24774916
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
 

Author Comment

by:DReade83
ID: 24774924
OK, what about Flex or Flash? Isn't that classed as a client-side application? Could that do the same thing as ActiveX?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 24774930
Ah, it's all about the client. Sorry for my lizard-brain idea...Ajax will be of no use here...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24774969
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
 

Author Comment

by:DReade83
ID: 24774977
Ah well, thanks man for your help, highly appreciated!
0
 
LVL 39

Expert Comment

by:abel
ID: 24775024
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
 
LVL 2

Expert Comment

by:ChrisDrake
ID: 24946434
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
 
LVL 39

Expert Comment

by:abel
ID: 24949449
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now