Solved

Email Notification when server is logged into remotely.

Posted on 2007-11-19
15
483 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
 
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now