'@Author :- Dinesh Kumar Version :- 1.0' On Error Resume Next Dim start_date Dim end_date Dim input_value Dim hours Dim minutes Dim Total_time_spent Dim septxt Dim logPathname Dim colon Dim today_date Dim objFSO, strInput, objInput Dim arrValues, strItem, strLine Dim strOutput, objOutput Public total Dim NewLine Dim Total_message Const ForReading = 1 Const ForWriting = 2 Const Space = " " NewLine = "\n" Total_message = "TOTAL HOURS FOR" Function convertTime(seconds) ConvSec = seconds Mod 60 If Len(ConvSec) = 1 Then ConvSec = "0" & ConvSec End If ConvMin = (seconds Mod 3600) \ 60 If Len(ConvMin) = 1 Then ConvMin = "0" & ConvMin End If ConvHour = seconds \ 3600 If Len(ConvHour) = 1 Then ConvHour = "0" & ConvHour End If convertTime = ConvHour & ":" & ConvMin & ":" & ConvSec End Function Function CSVParse(ByVal strLine) ' Function to parse comma delimited line and return array ' of field values. Dim arrFields Dim blnIgnore Dim intFieldCount Dim intCursor Dim intStart Dim strChar Dim strValue Const QUOTE = """" Const QUOTE2 = """""" ' Check for empty string and return empty array. If (Len(Trim(strLine)) = 0) then CSVParse = Array() Exit Function End If ' Initialize. blnIgnore = False intFieldCount = 0 intStart = 1 arrFields = Array() ' Add "," to delimit the last field. strLine = strLine & "," ' Walk the string. For intCursor = 1 To Len(strLine) ' Get a character. strChar = Mid(strLine, intCursor, 1) Select Case strChar Case QUOTE ' Toggle the ignore flag. blnIgnore = Not blnIgnore Case "," If Not blnIgnore Then ' Add element to the array. ReDim Preserve arrFields(intFieldCount) ' Makes sure the "field" has a non-zero length. If (intCursor - intStart > 0) Then ' Extract the field value. strValue = Mid(strLine, intStart, _ intCursor - intStart) ' If it's a quoted string, use Mid to ' remove outer quotes and replace inner ' doubled quotes with single. If (Left(strValue, 1) = QUOTE) Then arrFields(intFieldCount) = _ Replace(Mid(strValue, 2, _ Len(strValue) - 2), QUOTE2, QUOTE) Else arrFields(intFieldCount) = strValue End If Else ' An empty field is an empty array element. arrFields(intFieldCount) = Empty End If ' increment for next field. intFieldCount = intFieldCount + 1 intStart = intCursor + 1 End If End Select Next ' Return the array. CSVParse = arrFields End Function septxt = ", " colon = ": " today_date= FormatDateTime(Now(), vbShortDate) logPathname = "C:\Dinesh\LOGFILE.csv" input_value = Wscript.Arguments.Item(0) Function FileObject() Set objShell = CreateObject("WScript.Shell") Set objEnv = objShell.Environment("USER") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile (logPathname, ForAppending, True) End Function ''''''''''''''''''''''''''''''''''''''' ' User Name Section ''''''''''''''''''''''''''''''''''''''' set wsNetwork = createobject("WSCRIPT.Network") outUser=wsNetwork.UserName If input_value = "UNLOCK" Then objEnv("UNLOCK_TIME") = FormatDateTime(Now(), vbGeneralDate) Total_time_spent = objEnv("Total_time_spent") Wscript.Echo "Time Usage last login : " & Total_time_spent WScript.Quit ''''''''''''''''''''''''''''''''''''''' ' LOCK Section ''''''''''''''''''''''''''''''''''''''' ElseIf input_value = "LOCK" Then start_date = objEnv("UNLOCK_TIME") end_date = FormatDateTime(Now(), vbGeneralDate) Total_time_spent = convertTime(DateDiff("s",start_date,end_date)) objEnv("Total_time_spent") = Total_time_spent Const ForAppending = 8 ''''''''''''''''''''''''''''''''''''''' ' output Section ''''''''''''''''''''''''''''''''''''''' 'objTextFile.WriteLine( & start_date & septxt & end_date & septxt & outUser & septxt & Total_time_spent ) 'objTextFile.WriteLine(FormatDateTime(Now(), vbGeneralDate) & septxt & outUser & septxt & outComputer) objTextFile.WriteLine(+ FormatDateTime(start_date,vbShortDate) + septxt + FormatDateTime( start_date,vbShortTime) + septxt +FormatDateTime(end_date,vbShortTime) + septxt + outUser + septxt + Total_time_spent) objTextFile.Close WScript.Quit ElseIf input_value = "FINAL_UNLOCK" Then start_date = objEnv("UNLOCK_TIME") strInput = "c:\Dinesh\LOGFILE.csv" total = 0 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInput = objFSO.OpenTextFile(strInput, ForReading) ' Open the output file for writing. Set objOutput = objFSO.OpenTextFile(strOutput, ForWriting, True) ' Read the file. Do Until objInput.AtEndOfStream strLine = objInput.ReadLine ' Skip blank lines. If (Trim(strLine) <> "") Then ' Parse the fields in the file. arrValues = CSVParse(strLine) ' Write the value in the third field to the output file. total = int(DateDiff("s","00:00:00",arrValues(4))) + total End If Loop wscript.echo total FileObject() objTextFile.WriteLine ( +space ) objTextFile.Close FileObject() Wscript.echo (+ Total_message + start_date + colon + convertTime(total)) objTextFile.WriteLine ( + Total_message + start_date + colon + convertTime(total) ) objTextFile.Close FileObject() objTextFile.WriteLine ( +space ) objTextFile.Close FileObject() objTextFile.WriteLine ( +space ) objTextFile.Close WScript.Quit ' Clean up. objInput.Close objOutput.Close End If
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more