Skip to main content

SystemInfo project

8 replies [Last post]
prophecy
Offline
Joined: 2003-09-03

Where is this at in terms of stability and is there any documentation on it?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cdea
Offline
Joined: 2011-03-01

> One more thing regarding the idletime feature:
> I have also seen examples where the code fired an
> event when the system had been idle for a certain
> amount of time (as opposed to pulling the value on
> demand all the time). This could be useful, for
> example changing the icon of the TrayIcon when you
> have been away from the computer for 10 mins, or set
> an away message for an IRC application.
>
>
> Anyway, just posting my ideas :)

Thanks for the suggestions.

We are aware of those articles and MSDN tech notes.
You may want to look at our code. Its very similar to your ideas.

Regarding the hooks to intercept keyboard and mouse events. In a corporate intranet environment this may not be a good (safe) idea.

If you could try to help us test it that would be greatly appreciated.

We need more feedback.

-Carl Dea

boerkel
Offline
Joined: 2003-08-10

About determing, if the session is remote or local: I have implemented that using JNA. This is the code:

JNA's Kernel32.java:
public int GetCurrentProcessId();
public boolean ProcessIdToSessionId(int dwProcessId, IntByReference pSessionId);
public int WTSGetActiveConsoleSessionId();

My code:
public static boolean isLocalSession() {
Kernel32 kernel32;
IntByReference pSessionId;
int consoleSessionId;

kernel32 = Kernel32.INSTANCE;
pSessionId = new IntByReference();

if(kernel32.ProcessIdToSessionId(kernel32.GetCurrentProcessId(), pSessionId)) {

consoleSessionId = kernel32.WTSGetActiveConsoleSessionId();

if(consoleSessionId != 0xFFFFFFFF && consoleSessionId == pSessionId.getValue()) {
return(true);
}
}
return(false);
} // isLocalSession

John Ellis

Right now we're working on both. Currently the desktop locked method
runs under Win2k/XP, and the idle time works in Linux, Solaris and
Win2k/XP. I'm working on code to get the idle time to work under
Win95/98 as well.

Once I finish up the idle time functionality I'm going to document and
javadoc everything, then post appropriate docs on the SystemInfo page.
You should (hopefully, if all the native stuff goes well) see some
docs pop up next week.

Stability hasn't been proven yet, but feel free to take it for a whirl!

On Apr 8, 2005 12:21 PM, jdic@javadesktop.org wrote:
> Where is this at in terms of stability and is there any documentation on it?
> ---
> [Message sent by forum member 'prophecy' (prophecy)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=70253
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
> For additional commands, e-mail: jdic-help@jdic.dev.java.net
>
>

--
John Ellis
john.ellis@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
For additional commands, e-mail: jdic-help@jdic.dev.java.net

tlund_
Offline
Joined: 2005-04-21

I'm looking forward to this one.

I implemented a getSystemIdleTime with JNI for WinXP myself a year ago, because i needed it for a small desktop app i was writing. My skills with c++ and the windows native api are not that good, but this was a fairly straightforward task.

How are you implementing this on windows?
I implemented it using GetTickCount() and GetLastInputInfo(), and if i remember correct, GetTickCount() returned a DWORD, so the time will wrap around to zero if the system is run continuously for 49.7 days. Are you adding any code to work around this issue?

I'm also not sure if these methods support multi session environments (have only tested it on Windows XP). Are these methods returning "global" system values?

Another feature I was planning to implement was some status information about the current session, eg if it was a "local" or "remote" session (remote desktop on windows, remote shell/console on linux). Maybe not a very useful feature, but i thought it would be nice for my app:

public final static int SESSION_TYPE_UNKNOWN = 0;

public final static int SESSION_TYPE_LOCAL = 1;

public final static int SESSION_TYPE_REMOTE = 2;

public int getCurrentSessionType()

Never actually got around to seeing this work though.

If some of you are interested in investegating this further, here is some info:

[b]"The WTSRegisterSessionNotification function registers the specified window to receive session change notifications. >> So your app can know when the state has changed (a remote session joins or not?).

The WTSEnumerateSessions function retrieves a list of sessions on a specified terminal server. >> In case you are writing a service (they do not usually have windows).

The WTSGetActiveConsoleSessionId function retrieves the Terminal Services session currently attached to the physical console. The physical console is the monitor, keyboard, and mouse. Note that it is not necessary that Terminal Services be running for this function to succeed. >> To distinguish if the 'current' session is remote or not.

The WTSQuerySessionInformation function retrieves session information for the specified session on the specified terminal server. It can be used to query session information on local and remote terminal servers. >> You can find out if session is rmeote or not, and all sorts of other infromation you might want to track.
"[/b]

The WTSQuerySessionInformation is probably the one you should use. This is part of the code I was working on, but never finished. (Don't think it works though) :

DWORD currentSessionId;
BOOL success = ProcessIdToSessionId(GetCurrentProcessId(),&currentSessionId);
DWORD sessionId = WTSGetActiveConsoleSessionId();
if(currentSessionId == sessionId){ //The process session is the same as the console session
sessionStatus = (jbyte)0x02; //Local session
}else if(sessionId == 0xFFFFFFFF){
sessionStatus = (jbyte)0x02; //Local session
}else sessionStatus = (jbyte)0x01; //Remote session

Anyway, having an getidletime implementation on more platforms than just windows would suit my app nicely.
Looking forward to seeing the docs and the code.

Thomas

tlund_
Offline
Joined: 2005-04-21

One more thing regarding the idletime feature:
I have also seen examples where the code fired an event when the system had been idle for a certain amount of time (as opposed to pulling the value on demand all the time). This could be useful, for example changing the icon of the TrayIcon when you have been away from the computer for 10 mins, or set an away message for an IRC application.

This can probably be accomplished by hooking into the OS's mouse and keyboard events, and resetting a Timer each time an event is fired. But i'm not sure if this is the best solution.
http://www.codeproject.com/dll/trackuseridle.asp

"To track a user's idle time you could hook keyboard and mouse activity. Note, however, that installing a system-wide message hook is a very invasive thing to do and should be avoided if possible, since it will require your hook DLL to be loaded into all processes.
"

Alternatively, have a method that watches the idle time at a given interval:
http://www.codeguru.com/Cpp/Cpp/cpp_managed/threads/article.php/c8347/

To sum it up:
1. The ability to get the systemidletime on request, and
2. To register an action to be fired when the system has been idle for a certain amout of time. (Maybe a 'SystemIdleTimer', much like the javax.swing.Timer class).

Anyway, just posting my ideas :)

John Ellis

Currently Carl Dea & myself are working on solutions using both the
Info API on Win2000/XP, as well as callbacks into the Win32 event
handler (Win95/98/NT). Both of the solutions you mentioned will be
applied, since different OS' require the different implementations.
Callbacks cause locking & resource problems at times, however, and can
lead to DLL hell.

Idle time itself and event management is left to the Java app itself -
the SystemInfo package should just pass along whatever idle info it
has. It's more property-driven than event-driven, since that's how
most window managers seem to handle it.

On 4/25/05, jdic@javadesktop.org wrote:
> One more thing regarding the idletime feature:
> I have also seen examples where the code fired an event when the system had been idle for a certain amount of time (as opposed to pulling the value on demand all the time). This could be useful, for example changing the icon of the TrayIcon when you have been away from the computer for 10 mins, or set an away message for an IRC application.
>
> This can probably be accomplished by hooking into the OS's mouse and keyboard events, and resetting a Timer each time an event is fired. But i'm not sure if this is the best solution.
> http://www.codeproject.com/dll/trackuseridle.asp
>
> "To track a user's idle time you could hook keyboard and mouse activity. Note, however, that installing a system-wide message hook is a very invasive thing to do and should be avoided if possible, since it will require your hook DLL to be loaded into all processes.
> "
>
> Alternatively, have a method that watches the idle time at a given interval:
> http://www.codeguru.com/Cpp/Cpp/cpp_managed/threads/article.php/c8347/
>
> To sum it up:
> 1. The ability to get the systemidletime on request, and
> 2. To register an action to be fired when the system has been idle for a certain amout of time. (Maybe a 'SystemIdleTimer', much like the javax.swing.Timer class).
>
> Anyway, just posting my ideas :)
> ---
> [Message sent by forum member 'tlund_' (Thomas Lund)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=74730
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
> For additional commands, e-mail: jdic-help@jdic.dev.java.net
>
>

--
John Ellis
john.ellis@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
For additional commands, e-mail: jdic-help@jdic.dev.java.net

mores
Offline
Joined: 2005-01-21

I see it has been a couple of years now.....

How can I retrieve the idle time using SystemInfo today ? Was this ever released ?

twalljava
Offline
Joined: 2004-07-26

Someone recently posted an idle time implementation using jna (http://jna.dev.java.net), which avoids the hassle of building or distributing any native JNI code.