Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim objFSO, objShell, objTextFile
- Dim strText
- Dim prevDate
- Dim prevTime
- Dim timeLeft
- Const strDirectory = "C:"
- Const strFile = "\timelog.txt"
- Const checkTimeLeftVbs = "C:\checktimeleft.vbs"
- Const ForAppending = 8
- Const ForReading = 1
- Const ForWriting = 2
- Dim usageTime 'in minutes
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objShell = WScript.CreateObject ("WScript.Shell")
- Function openLogFile(N)
- Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, N, True)
- End Function
- Function checkPrevInst()
- Call openLogFile(ForReading)
- prevDate = objTextFile.ReadLine
- prevTime = CInt(objTextFile.ReadLine)
- objTextFile.Close
- If prevDate <> "" Then
- If DateDiff("d", prevDate, Date) >= 1 Then
- Call logStartTime()
- Else
- 'Continue monitoring
- Call logTime()
- End If
- Else
- 'Log file compromised...
- Call logStartTime()
- End If
- End Function
- Function logStartTime()
- Call openLogFile(ForWriting)
- objTextFile.WriteLine(Date)
- objTextFile.WriteLine("0")
- objTextFile.Close
- prevDate = Date
- prevTime = 0
- Call logTime()
- End Function
- Function checkforChanges()
- Dim tempPrevDate
- Dim tempPrevTime
- Call openLogFile(ForReading)
- tempPrevDate = objTextFile.ReadLine
- tempPrevTime = CInt(objTextFile.ReadLine)
- objTextFile.Close
- If tempPrevDate = PrevDate Then
- If tempPrevTime <> prevTime Then
- prevTime = tempPrevTime
- timeLeft = usageTime - prevTime
- objShell.Run checkTimeLeftVbs
- End If
- End If
- End Function
- Function logTime()
- timeLeft = usageTime - prevTime
- objShell.Run checkTimeLeftVbs
- Do While timeLeft > 0
- Call openLogFile(ForWriting)
- objTextFile.WriteLine(prevDate)
- objTextFile.WriteLine(prevTime)
- objTextFile.WriteLine(timeLeft)
- objTextFile.Close
- WScript.Sleep 60000
- Call checkforChanges()
- prevTime = prevTime + 1
- timeLeft = usageTime - prevTime
- If timeLeft <= 5 Or timeLeft = 10 Or timeLeft = 15 Then
- objShell.Run checkTimeLeftVbs
- End If
- Loop
- 'Time exceeded
- Call timeExceeded()
- End Function
- Function timeExceeded()
- Do While timeLeft <= 0
- Call endSession()
- WScript.Sleep 10000
- Loop
- End Function
- Function endSession()
- objShell.Run "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation", 0, False
- End Function
- Function checkDay()
- If Weekday(Date, 1) <> "1" And Weekday(Date, 1) <> "6" And Weekday(Date, 1) <> "7" Then
- usageTime = 60 'weekday time, in minutes
- Else
- usageTime = 90 'weekend time, in minutes
- End If
- Call checkPrevInst()
- End Function
- 'Main program
- Call checkDay()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement