barrystone Posted March 24, 2015 Posted March 24, 2015 Hi Guys Looking for a way to generate email to administrator when a particular student logs on to domain. Basically need username and machine that he logged on to Thanks
JJonas Posted March 24, 2015 Posted March 24, 2015 we have this in our logon script echo %date% %time% %computername% %username% >>\\server\logon$\logons.txt echo %date% %time% %computername% >> \\server\logon$\users\%username%.txt echo %date% %time% %username% >> \\server\logon$\computers\%computername%.txt 2
Garacesh Posted March 25, 2015 Posted March 25, 2015 I'm going to jump in on this one 'cause we tried to do similar a while ago and just couldn't get it to work... Set wshNetwork = WScript.CreateObject( "WScript.Network" ) Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Notification: Monitored Account Logon" objMessage.From = "FROM EMAIL" objMessage.To = "TO EMAIL, TO EMAIL" objMessage.TextBody = ("User " & wshNetwork.UserName & " logged onto workstation " & wshNetwork.ComputerName & " at " & Now) objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "EMAIL SERVER" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send Theoretically, set that as a login script in AD and it should email the account, location and time.. But it doesn't work
Steve21 Posted March 25, 2015 Posted March 25, 2015 Const ADMIN_EMAIL = "[email protected]" Const SMTP_SERVER = "mySMTPserver" Const SMTP_PORT = 25 Const SMTP_SSL = False Const ENABLE_DEBUGGING = False Set WshNetwork = CreateObject("WScript.Network") Set objSysInfo = CreateObject("ADSystemInfo") set objShell = WScript.CreateObject("WScript.Shell") strUser = objSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser) dteTime = Time dteDate = Date strMessage = "A user has logged onto " & ComputerName & " with the following details: " _ & "Logon Date: " & dteDate & " " _ & "Logon Time: " & dteTime & " " _ & "Account Name: " & AccountName & " " 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 SendMail(strBody) Set objEmail = CreateObject("CDO.Message") With objEmail .From = ADMIN_EMAIL .To = ADMIN_EMAIL .Subject = "Logon Notification - " & AccountName .HTMLBody = strBody .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTP_PORT If SMTP_SSL Then .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True End If .Configuration.Fields.Update On Error Resume Next Err.Clear .Send If Err.number <> 0 Then SendMail = Err.Description Else SendMail = "The server did not return any errors." End If On Error Goto 0 End With End Function Is what we use. Steve
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now