Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Active Directory > answer

Reply
 
 
zacaria ranjoor
Guest
Posts: n/a

 
      05-30-2010

hi, exuz for bad english
u most frist calculate the inactive time.
In order to determine the period of inactivity, two times are required. The first is the system's up time and the second is the up time when the last user input occurred. If the second value is subtracted from the first, the duration of inactivity is known. Obtaining the first value.
The time of the last user input can be obtained using a call to the Windows API using Platform Invocation Services (P/Invoke).

As we will be using P/Invoke, ensure that you include the following using directive:
using System.Runtime.InteropServices;

Declaring GetLastInputInfo
The API function that we will use to obtain the time of the last user input is GetLastInputInfo. This function uses a structure, named "LASTINPUTINFO", which must be declared as follows:

[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}The structure has two fields. cbSize must be set to the size of the structure before GetLastInputInfo is called. dwTime will be set to the time of the last user input by the call to GetLastInputInfo. This returned value is measured in milliseconds.

With the structure defined, the GetLastInputInfo function can be added to the InactiveTimeRetriever class. Note the Boolean return value in the code below. A return value of false indicates that an error occurred whilst executing the function.

[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);


Obtaining the Inactive Time
The final task is to add a method to the InactiveTimeRetriever class that will return a TimeSpan containing the duration of inactivity. The return value will be nullable, with null indicating that there was a problem when calling GetLastInputInfo.

Add the following method to the class:

public TimeSpan? GetInactiveTime()
{
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = (uint)Marshal.SizeOf(info);
if (GetLastInputInfo(ref info))
return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime);
else
return null;
}The method performs several actions. Firstly, a LASTINPUTINFO value is created and its size initialised. This is then passed by reference to the GetLastInputInfo function. If the function returns true, the resultant time from the dwTime field is subtracted from the system up time and transformed into a TimeSpan value, which is returned. If GetLastInputInfo fails, null is returned.

see fuul article: http://www.blackwasp.co.uk/InactivityDetection.aspx




bguill00 wrote:

Force logoff after inactivity on public computer
02-Oct-07

I have one workstation that is used by all users. They log in, run a
specific application that only resides on this one computer and then
they are supposed to logoff. Well, they don't and this leaves the
computer logged in with access to data. How can I force users to
logoff after a period of inactivity on this one specific computer.
Everythign I've found related to forcing a logoff is based on the user
and not the computer. In other words, I can force user 1 to logoff
using the Winexit.scr but I can't set this up for everyone on only one
computer. Is there a way to force this one computer to logoff after a
period of inactivity regardless of who loggs in?

Previous Posts In This Thread:

On Tuesday, October 02, 2007 4:50 PM
bguill00 wrote:

Force logoff after inactivity on public computer
I have one workstation that is used by all users. They log in, run a
specific application that only resides on this one computer and then
they are supposed to logoff. Well, they don't and this leaves the
computer logged in with access to data. How can I force users to
logoff after a period of inactivity on this one specific computer.
Everythign I've found related to forcing a logoff is based on the user
and not the computer. In other words, I can force user 1 to logoff
using the Winexit.scr but I can't set this up for everyone on only one
computer. Is there a way to force this one computer to logoff after a
period of inactivity regardless of who loggs in?

On Tuesday, October 02, 2007 5:06 PM
Jorge Silva wrote:

HiYou can use Terminal Services to do that.
Hi
You can use Terminal Services to do that.

--

I hope that the information above helps you.
Have a Nice day.

Jorge Silva
MCSE, MVP Directory Services

On Wednesday, October 03, 2007 1:38 PM
bguill00 wrote:

Re: Force logoff after inactivity on public computer
On Oct 2, 5:06 pm, "Jorge Silva" <jorgesilva...@hotmail.com> wrote:

Not sure where Terminal Services fits into this unless you mean to
have the program they use run onTerminal Services and then I can
control the sessions. Only problem with that is the application is
not licensed for terminal services and that still leaves the
workstation logged in to the network even if the Terminal Services
session is terminated. I need to have one workstation log itself off
when it is inactive for a given period of time regardless of who is
logged into it.

On Wednesday, October 03, 2007 2:11 PM
Jorge Silva wrote:

In TS you can control sessions behavior, that's why I mentioned.
In TS you can control sessions behavior, that's why I mentioned. However if
you can't rrun that app in TS mode, you'll probably need an external vendor
solution that does what you want.

--

I hope that the information above helps you.
Have a Nice day.

Jorge Silva
MCSE, MVP Directory Services

"bguill00" <> wrote in message
news: oups.com...


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Customized Find Control for FlowDocuments
http://www.eggheadcafe.com/tutorials...ind-contr.aspx
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Answer file local admin password Willie Eckerslike Windows Server 0 01-21-2010 08:35 AM
Re: Where should I be asking this to get an answer? Paul G. Tobey [eMVP] ActiveSync 3 07-20-2009 07:29 PM
Sysprep answer file.....WHY!?!?!? Rich Martinez (RRCC) Windows Vista Installation 2 06-24-2007 06:43 PM
Re: Vista 32bit can't recognize all the memory: Answer from MS Peter Meinl Windows Vista Performance 0 12-08-2006 04:14 PM
Re: Treo 700w cannot answer calls when MSFP has locked screen Rich Matheisen [MVP] ActiveSync 0 08-12-2006 02:52 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59