|
-
Aug 12th, 2000, 10:21 PM
#1
Thread Starter
New Member
I want to write a program that would log a user off from an Winnt 4 workstation or a Windows 2000 prof. machine if he has been idle (if the keyboard or mouse hasn't been used for, say an hr).
Can anyone offer any suggestions or code snippets as to how I should go about doing this? Thanks.
-
Aug 13th, 2000, 10:23 AM
#2
Monday Morning Lunatic
If you intercepted the keyboard handler, then you could have a loop which uses GetTickCount, and when the difference got to high without an event, then log them off.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 13th, 2000, 10:29 AM
#3
Good Ol' Platypus
Use the GetAsyncKeyState to find out if it's been null. Then, after an hour, if it's still null, then shut down the computer. I'm sure there's a call you can make to do that. Also, you should enumerate the windows and use TerminateProcess API to close 'em. BTW: Make sure to reset the timer when a key is pressed.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Aug 13th, 2000, 10:30 AM
#4
Fanatic Member
to log them off, just use the ExitWindowsEx API function, with the Log-Off Parameter
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Aug 13th, 2000, 10:34 AM
#5
Try this: Make a Form with a Timer and put the following code into it.
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_LOGOFF = 0
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim CurPos As POINTAPI
Dim OldX As Single
Dim OldY As Single
Dim StartTime As Date
Function Start()
'Create a StartTime
StartTime = Format(Time, "hh:mm:ss")
End Function
Private Sub Form_Load()
'Give a StartTime when the Form loads
Start
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
'Loop through the keys and see if they were pressed
For I = 32 To 127
If GetAsyncKeyState(I) Then Start
'Do the same for the Mouse Buttons
If GetAsyncKeyState(vbLeftButton) Then Start
If GetAsyncKeyState(vbRightButton) Then Start
Next
'Check if mouse is still
MyPos = GetCursorPos(CurPos)
X = CurPos.X
Y = CurPos.Y
If OldX = X And OldY = Y Then
'The mouse is still
Else
'the Mouse is not still
OldX = X
OldY = Y
'Create a new StartTime
Start
End If
'Subtract the current time with the StartTime
Retval = StartTime - Time
Retval = Format(Retval, "hh:mm:ss")
'If it's been 1 hour then log-off
If Retval = "01:00:00" Then
ExitWindowsEx EWX_LOGOFF, 0&
End If
End Sub
-
Aug 13th, 2000, 01:37 PM
#6
Thread Starter
New Member
Thanks!
I used your suggestions (polling the keyboard and mouse and using ExitWindowsEx to force them off) and its working. I just have a couple more questions about this:
These machines are networked....does ExitWindowsEx log the user off the server as well or just the local machine?
Another problem now is to hide it from the Task Manager so that normal users cannot see it.The only way I can think of doing this is by making this into a service (I think the NTSVC.OCX is used for that).
The thing I am afraid of is that this service will run even when someone is not logged on,... so what happens when an hour elapses and the computer logs off a user when there is NO user logged on? Is there a way to detect that there is no user logged onto the machine?
Is there any other way to hide from NT and win2k task manager without making the app into a service?
-
Aug 13th, 2000, 02:49 PM
#7
Fanatic Member
There is code here at vb world to hide it from the task manager, also, using the QueryUnload event, you could make it so that if they used the task manager to get rid of it, it would log them off. You could probably find out if there is a user using the GetUserName API.
Code:
Public Declare Function GetCurrentProcessId _
Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess _
Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess _
Lib "kernel32" (ByVal dwProcessID As Long, _
ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0
Public Sub MakeMeService()
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub
Public Sub UnMakeMeService()
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, _
RSP_UNREGISTER_SERVICE)
End Sub
Use MakeMeService to Hide
in unload or queryunload use UnMakeMeService.
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Aug 13th, 2000, 05:28 PM
#8
Thread Starter
New Member
I have tried using RegisterServiceProcess in Winnt but I can't get it to work. It works perfectly in Win9x though.
How can I check if the QueryUnload event has been raised?
-
Aug 13th, 2000, 06:04 PM
#9
Fanatic Member
it's a form event. ie. Form_QueryUnload(UnloadMode as integer) or something like that
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Aug 13th, 2000, 06:07 PM
#10
For Windows NT, you can hide your App using the following code.
Code:
App.TaskVisible = False
-
Aug 14th, 2000, 12:50 AM
#11
Thread Starter
New Member
Is there a way I can create some sort of global mouse hook in VB that can catch any mouse activity (not just over my window)?
Would that be better or worse than polling the mouse for this app?
-
Jan 19th, 2002, 11:33 PM
#12
Hyperactive Member
Megatron!!!
Thanks for your code... That works great! I had tried to create the same with poor results.. hahahahhah
Yours will do the trick just fine!
-
Jan 19th, 2002, 11:45 PM
#13
Originally posted by Baadshah628
The thing I am afraid of is that this service will run even when someone is not logged on,... so what happens when an hour elapses and the computer logs off a user when there is NO user logged on? Is there a way to detect that there is no user logged onto the machine?
It will run, but it will return with an error -- something like "WM_NotLoggedOn". It's only posted to the Messaging Subsystem, so it shouldn't be a problem.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|