Advertisement
Huttie

LastBootUpTime

Nov 17th, 2015
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. On Error Resume Next
  2. userprofile = "HKEY_CURRENT_USER\Volatile Environment\USERNAME"
  3. userdomain_temp = "HKEY_CURRENT_USER\Volatile Environment\USERDOMAIN"
  4. Set objshell = CreateObject("Wscript.Shell")
  5. username = objshell.RegRead(userprofile)
  6. userdomain = objshell.RegRead(userdomain_temp)
  7. strComputer = "."
  8. Set objWMIService = GetObject("winmgmts:" _
  9.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  10.  
  11. Set objOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
  12.  
  13. Function WMIDateStringToDate(dtmLastBootUpTime)
  14.     WMIDateStringToDate = CDate(Mid(dtmBootDate, 7, 2) & "/" & _
  15.         Mid(dtmBootDate, 5, 2) & "/" & Left(dtmBootDate, 4) _
  16.             & " " & Mid (dtmBootDate, 9, 2) & ":" & _
  17.                 Mid(dtmBootDate, 11, 2) & ":" & Mid(dtmBootDate, _
  18.                     13, 2))
  19. End Function
  20.  
  21.  
  22. For Each strOS in objOS
  23.  
  24.     dtmBootDate = strOS.LastBootUpTime
  25.     strReturn = WMIDateStringToDate(dtmBootDate)
  26.     strNow = Now   
  27.     daydifference=DateDiff("d", strReturn, strNow)
  28.  
  29.     If daydifference=>7 Then
  30.         msgbox"It is now " & daydifference & " days since you last restarted your computer" & vbNewLine _
  31.         & "We recommend that you restart your computer when convenient, to make sure you recieve the newest security updates" &     vbNewLine & vbNewLine & _
  32.         "Best regards" & vbNewLine & "Columbus Corporate IT",4096+0,"Message from Columbus Corporate IT"
  33.    
  34. Next
  35.  
  36.  
  37. Const ForReading = 1
  38. Const ForWriting = 2
  39. Set objFSO = CreateObject("Scripting.FileSystemObject")
  40. Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForReading)
  41.  
  42. strText = objFile.ReadAll
  43. objFile.Close
  44.  
  45.  
  46. strArray = Split(strText, vbCrLf)
  47. For Each item in strArray
  48.  If InStr(item, username) <> 0 Then        
  49.  strOldText = item
  50.  End If
  51. Next  
  52.  
  53.     strNewText = Replace(strText, strOldText, username & " | " & userdomain & " | " & Daydifference & " | " & Now)
  54.    
  55.     Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForWriting)
  56.     objFile.Write strNewText
  57.     objFile.Close
  58.  
  59.              
  60. if instr(strText, username) = 0 Then
  61.     Const ForAppending = 8
  62.     Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForAppending)
  63.     objFile.WriteLine username & " | " & userdomain & " | " & Daydifference & " | " & Now
  64.     objFile.Close
  65. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement