' Logon Notification
' This script can be run as a logon script to send email notification
' when a user logs on to a system. Details about the logon event are
' included in the email.
' LogonNotification.vbs
' © Robert Dunham - 11/20/2007
' Created by Nilpo for ASP Free Forums
' You may use or modify this script in any way as long as this copyright remains intact.
' Webpage: http://www.nilpo.com/pub/scripts/LogonNotification.vbs
' Please indicate where notifications should be sent
Const ADMIN_EMAIL = "recipient@mail.com"
' Please provide the following details for your SMTP server
Const SMTP_SERVER = "smtp.mail.com"
Const SMTP_PORT = 25 ' Do not change if you are unsure
' If your SMTP server requires authentication, please set
' USE_AUTHENTICATION to True and supply a username and password
Const USE_AUTHENTICATION = False
Const SMTP_USER = "username"
Const SMTP_PASS = "password"
' If your SMTP server uses Secure Password Aunthentication, please
' set the following value to True.
Const SMTP_SSL = False
' Set this value to true while testing
Const ENABLE_DEBUGGING = False
' Do not change anything below this line
Set WshNetwork = CreateObject("WScript.Network")
dteTime = Time
dteDate = Date
strMessage = "A user has logged onto " & ComputerName & " from " & WAN_IP & " with the following details:
" _
& "Logon Date: " & dteDate & "
" _
& "Logon Time: " & dteTime & "
" _
& "Account Name: " & AccountName & "
" _
& "LAN IP: " & LAN_IP & "
"
result = SendMail(strMessage)
If ENABLE_DEBUGGING Then WScript.Echo result
WScript.Quit
Function AccountName
If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network")
AccountName = WshNetwork.UserName
End Function
Function ComputerName
If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
End Function
Function LAN_IP
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE",,48)
For Each objItem In colItems
If Not IsNull(objItem.IPAddress) Then
LAN_IP = objItem.IPAddress(0)
Exit For
End If
Next
End Function
Function WAN_IP
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("get", "http://checkip.dyndns.org", False)
objxmlHTTP.Send()
strHTMLText = objxmlHTTP.ResponseText
Set objxmlHTTP = Nothing
If strHTMLText <> "" Then
varStart = InStr(1, strHTMLText, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTMLText, "