Solved

Email Notification when server is logged into remotely.

Posted on 2007-11-19
15
507 Views
Last Modified: 2010-04-21
I am wondering if there is a software package out there that would sent an admin and email everytime one of the servers in in environment has been accessed via Terminal Services. I would like to be notified whenever anyone logges directly into the server.
0
Comment
Question by:jlycos1
  • 10
  • 5
15 Comments
 
LVL 5

Expert Comment

by:JohnDemerjian
ID: 20314957
don't know if there is a third party package, but you could create a login script that simply sends you an email when it runs.  that way whenever anyone logs onto the server either locally or remotely the script will run and send you an email.  
0
 
LVL 5

Expert Comment

by:JohnDemerjian
ID: 20315011
here is a vbscript that will send an email.  run it from a batch file with the command "cscript email.vbs" assuming you call the file email.vbs
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "This is the subject of the email" 
objMessage.Sender = "your_name@company.com" 
objMessage.To = "john_jones@company.com, joe.smith@company.com"
objMessage.TextBody = "The network is down, but I'm feeling better."
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.company.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send 
Open in New Window 

Open in new window

0
 
LVL 1

Author Comment

by:jlycos1
ID: 20315956
Is there a way to let you know who they logged in as.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Author Comment

by:jlycos1
ID: 20315972
Can I place this is the startup folder....
0
 
LVL 5

Expert Comment

by:JohnDemerjian
ID: 20316047
i'm sure you could get the user name into the email somehow, but you'd need to poke around on the net.  you wouldn't need to place it in a startup folder if you made an OU for the servers, put a GP in place and then ran this as a login script on the OU.  that's one way to do it anyway.  here's a post that may help capture that user name.  a sloppy way (what i would probably do) is to have %username% dumped into a text file and then attach that file to the email and send.  this is very sloppy from a programatical sense but it would work if you are not able to piece together the exact script you want.
0
 
LVL 1

Author Comment

by:jlycos1
ID: 20316166
I have the vbs with my email as the sender and reciever with the exchnage server name as the smtp server and still no emails to my inbox. I am just executing the vbs using th cmd prompt  with the location of c: for testing.
0
 
LVL 1

Author Comment

by:jlycos1
ID: 20316176
I removed Open in New Window from the script because I was receiving a syntax issue on line 26.
0
 
LVL 1

Author Comment

by:jlycos1
ID: 20316245
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "DC Has been Logged Into"
objMessage.Sender = "BlaBla@mydmain.com"
objMessage.To = "blabla@mydomain.com"
objMessage.TextBody = "Someone logged into DC"
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "exchange1"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send
0
 
LVL 1

Author Comment

by:jlycos1
ID: 20319818
Whenever I enter the command cscript email.vbs on the root of c: and hit enter I get a little symantec window in the lower left letting me know that it "Scanning Message 1 of 1" but I do not see it in my email. Anyhelp would be helpful.
0
 
LVL 5

Accepted Solution

by:
JohnDemerjian earned 250 total points
ID: 20319979
The orignal script is working fine and you should disable the symantec app that is causing a problem temporarily.  Also, your Exchange server may need you to add the IP address of the servers that are trying to run the script into the list of servers allowed to relay.  Finally, the attached script adds the user name and computer name to the text of the message...
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "DC Has been Logged Into" 
objMessage.Sender = "jdemerjian@company.com" 
objMessage.From = "John Demerjian"
objMessage.To = "jdemerjian@company.com"
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
objMessage.TextBody = strUserName & " logged into DC " & strComputerName
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.company.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send

Open in new window

0
 
LVL 1

Author Comment

by:jlycos1
ID: 20320249
I have it working now with the script below:

' ------ SCRIPT CONFIGURATION ------
strFrom = "bla@bla.com"
strTo = "bla@bla.com"
strSub = "Backup Has been Logged Into"
strBody = "Someone logged into Backup"
strSMTP = "smtp.bla.com"
' ------ END CONFIGURATION ---------
set objEmail = CreateObject("CDO.Message")
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSub
objEmail.Textbody = strBody
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.0.0.110"
objEmail.Configuration.Fields.Update
objEmail.Send
WScript.Echo "Email sent"

You had mentioned a sloppy way to include the name of the user that logged in, where did nyou find that?
0
 
LVL 5

Expert Comment

by:JohnDemerjian
ID: 20320400
cool, i'm glad it works.  actually i put a clean way together.  see the post above, but the text you are interested in is:


Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
objMessage.TextBody = strUserName & " logged into DC " & strComputerName

Open in new window

0
 
LVL 1

Author Comment

by:jlycos1
ID: 20321214
Where would this username portion be placed within the script?
0
 
LVL 1

Author Comment

by:jlycos1
ID: 20321313
Sorry I see the post above.....Works perfect......
0
 
LVL 1

Author Closing Comment

by:jlycos1
ID: 31409973
Great Script.....Everyone should use.....
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question