Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- On Error Resume Next
- userprofile = "HKEY_CURRENT_USER\Volatile Environment\USERNAME"
- userdomain_temp = "HKEY_CURRENT_USER\Volatile Environment\USERDOMAIN"
- Set objshell = CreateObject("Wscript.Shell")
- username = objshell.RegRead(userprofile)
- userdomain = objshell.RegRead(userdomain_temp)
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set objOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
- Function WMIDateStringToDate(dtmLastBootUpTime)
- WMIDateStringToDate = CDate(Mid(dtmBootDate, 7, 2) & "/" & _
- Mid(dtmBootDate, 5, 2) & "/" & Left(dtmBootDate, 4) _
- & " " & Mid (dtmBootDate, 9, 2) & ":" & _
- Mid(dtmBootDate, 11, 2) & ":" & Mid(dtmBootDate, _
- 13, 2))
- End Function
- For Each strOS in objOS
- dtmBootDate = strOS.LastBootUpTime
- strReturn = WMIDateStringToDate(dtmBootDate)
- strNow = Now
- daydifference=DateDiff("d", strReturn, strNow)
- If daydifference=>7 Then
- msgbox"It is now " & daydifference & " days since you last restarted your computer" & vbNewLine _
- & "We recommend that you restart your computer when convenient, to make sure you recieve the newest security updates" & vbNewLine & vbNewLine & _
- "Best regards" & vbNewLine & "Columbus Corporate IT",4096+0,"Message from Columbus Corporate IT"
- Next
- Const ForReading = 1
- Const ForWriting = 2
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForReading)
- strText = objFile.ReadAll
- objFile.Close
- strArray = Split(strText, vbCrLf)
- For Each item in strArray
- If InStr(item, username) <> 0 Then
- strOldText = item
- End If
- Next
- strNewText = Replace(strText, strOldText, username & " | " & userdomain & " | " & Daydifference & " | " & Now)
- Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForWriting)
- objFile.Write strNewText
- objFile.Close
- if instr(strText, username) = 0 Then
- Const ForAppending = 8
- Set objFile = objFSO.OpenTextFile("\\Sharename\ScriptLog.csv", ForAppending)
- objFile.WriteLine username & " | " & userdomain & " | " & Daydifference & " | " & Now
- objFile.Close
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement