Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS Script to determine idle time on computer without using SS timeout

Status
Not open for further replies.
Mar 23, 2011
1
0
0
US
thread329-1360519

"I need to come up with a way to determine if a user is logged into a machine or not and if the user is logged into the machine how long the machine has been in an idle state.

We have a TON of users who leave their computers up 24/7 but we have to do maintenance on machines. On the same note these users won't call me back when I need to arrange for me to do maintenance.

My boss said anyone who is idle on their PC for a long period of time is safe to kick off but I don't see any way to validate the user has been idle and I don't want a he said/she said situation.

I want to query and find out if a user is currently logged in and if the user is logged in how long the machine has been inactive."

------Has a solution been posted to this question. I's having the same issue-----
 
VBS is not the solution. Do you use Group Policy? If so, there is a group policy option to log off users after a specified idle time.

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Although, I actually read the link you posted and began to think that GPO would solve only part of your problem - making the computer available. How do you know if the computer is in use or not.

1. Check the registry to see who that last user was.
2. Check the .DateLastModified time of the user's registry file(NTUSER.DAT)
3. If it's been more than 3 hours, take control.

Code:
CONST HKLM = &h80000002
strComputer = "accountingPC"
set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

'1. Check the registry to see who that last user was.
objReg.GetStringValue HKLM, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", strLastUser

'2. Check the .DateLastModified time of the user's registry file(NTUSER.DAT)
strModified = objFSO.GetFile("\\" & strComputer & "\C$\Documents and Settings\" & strLastUser & "\NTUSER.DAT").DateLastModified

'3. If it's been more than 3 hours, take control.
if (datediff("n", strModified, now) > 180) then
   msgbox "The computer is available"
else
   msgbox "The computer is in use by " & strLastUser
end if

-Geates


"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top