Setting a time limit a user can use a computer

From Wiki

Jump to:navigation, search

Script Language: VBS

Type: Logon with loopback

Forum topic Link: http://www.edugeek.net/forums/wiki-announcements/19524-setting-time-limit-user-can-use-computer.html#post193407

This script can limit the amount of time a user can use a computer. It will automatically log the user off after 30 minutes giving the user several warnings when the time will expire.

To apply this Script, use it as a logon script with loopback on a computer organisational unit.

<vb>on error resume next dim TimeOff, sComputer, Time5min, Time4min, Time3min, Time2min, Time1min, ChangeTime

sComputer = "." ChangeTime = 30

Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & sComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_

    & " where Primary=true")

SetLocale(2057) if time >"00:00:01" and time<"13:14:00" then WSCript.Quit if time >"13:45:00" and time<"23:59:59" then WSCript.Quit


'System Time

TimeOff = DateAdd ("N",ChangeTime,Time()) Time5min = DateAdd ("N",ChangeTime - 5,Time()) Time4min = DateAdd ("N",ChangeTime - 4,Time()) Time3min = DateAdd ("N",ChangeTime - 3,Time()) Time2min = DateAdd ("N",ChangeTime - 2,Time()) Time1min = DateAdd ("N",ChangeTime - 1,Time())

SHOWBOX "You now have " & ChangeTime & " minutes on the system and your computer will logoff at " & TimeOff, 7


'Check Time

Do Until time > timeoff If Time > Time5min AND Time < Time4min then SHOWBOX "You now have approximately 5 minutes remaining on the system" & VBCR & "We kindly advise you to save your work", 7 End If

If Time > Time4min AND Time < Time3min then SHOWBOX "You now have approximately 4 minutes remaining on the system" & VBCR & "We kindly advise you to save your work", 7 End If

If Time > Time3min AND Time < Time2min then SHOWBOX "You now have approximately 3 minutes remaining on the system" & VBCR & "We kindly advise you to save your work", 7 End IF

If Time > Time2min AND Time < Time1min then SHOWBOX "You now have approximately 2 minutes remaining on the system" & VBCR & "We kindly advise you to save your work", 7 End If

If Time > Time1min AND Time < Timeoff then SHOWBOX "You now have approximately 60 seconds remaining on the system" & VBCR & "We kindly advise you to save your work", 7 End IF Timetowait 60 Loop

SHOWBOX "Your time has run out on the system, you will now be logged off," & VBCR & "Thank you for using the Library", 7

call logmeoff

wscript.quit


'Log the Computer off

Sub logmeoff 'Call WMI query to collect parameters for reboot action

   Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & sComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_
    & " where Primary=true") 
   Const EWX_LOGOFF = 0 
   Const EWX_SHUTDOWN = 1 
   Const EWX_REBOOT = 2 
   Const EWX_FORCE = 4 
   Const EWX_POWEROFF = 8 
       For each OpSys in OpSysSet 
          opSys.win32shutdown EWX_LOGOFF + EWX_FORCE
       Next

End Sub


'Pause Script

Sub TimeToWait( intSeconds )

   WScript.Sleep intSeconds * 1000

End Sub


'Showbox

Sub ShowBox( strMessage, nSeconds ) Set objshell = CreateObject("WScript.Shell") dEndTime = DateAdd("s",nSeconds,Now) While Now < dEndTime timeLeft = DatePart( "s",dEndTime - Now) If timeLeft > 0 Then objshell.Popup strMessage,timeLeft,"This message will self terminate in: " & timeLeft & " seconds.",0 + 64 End If Wend End Sub</vb>

You may need to change this code:

<vb> SetLocale(2057) if time >"00:00:01" and time<"13:14:00" then WSCript.Quit if time >"13:45:00" and time<"23:59:59" then WSCript.Quit </vb>

This will not run the script if it is not dinner time, if you wish to alter the times of your dinner time you can do that there. If you want it to take effect all the time just remove this code