Solved

smtp alert needed that checks ie version and sp level and sends an smtp alert to several recipients if they are not what they are meant to be

Posted on 2011-09-27
14
213 Views
Last Modified: 2012-06-27
Hi

We want all of our domain workstations to send us an SMTP alert automatically if they have a Service Pack that is anything other than SP3 and a web browser that is different to Internet Explorer 8.  Ideally we would want this to happen when the machines boot-up so it is obviously going to be a startup script of some kind.  Perhaps we can implement this through Group Policy.

We have a W2K3 domain with approximately 200 workstations and all are running Windows XP SP3 IE8.

Please help this is an urgent requirement

Thanks
0
Comment
Question by:richardstuartpowell
  • 7
  • 6
14 Comments
 
LVL 8

Expert Comment

by:jawa29
ID: 36709583
Hi Rich

Hope this does the trick...

Change the following variables at the top of the script and test run it first.

sFromAddress
sToAddress
sEMailServer
sEMailPort

If you want to see if it will send the email then uncomment line 43.

Jawa29
Const HKEY_LOCAL_MACHINE = &H80000002

'On Error Resume Next

sFromAddress = "someone@domain.com"
sToAddress = "someone@domain.com"
sEMailServer = "smtpserver"
sEMailPort = 25

' Get local hostname
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set wmiColl = oWMIService.ExecQuery("Select * FROM Win32_ComputerSystem")
For Each wmiobj In wmiColl
	sHostName = UCase(wmiobj.Name)
Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'Check registry for IE Version
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue

If Left(sValue, 1) <> "8" Then
	sErr = 1
	sText = "Internet Explorer version " & sValue
End If

' Get Service Pack level
Set colOSes = oWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
	sOS = objOS.Caption
	sSP = objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
Next

If Left(sSP, 1) <> "3" Then
	sErr = 1
	sText = sText & "Service Pack Version " & sOS & " " & sSP
End If

'If one of the values was wrong Then send the email
'sErr = 1
If sErr = 1 Then

	Set oEmail = CreateObject("CDO.Message")

	oEmail.From = sFromAddress
	oEmail.To = sToAddress
	oEmail.Subject = "IE Version & SP Version Report for " & sHostName
	oEmail.Textbody = sText
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sEMailServer
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sEMailPort
	oEmail.Configuration.Fields.Update
	oEmail.Send

End If

Open in new window

0
 
LVL 10

Expert Comment

by:akhalighi
ID: 36709602
I've done something similar to this , I wanted to get a report of McAfee versions across my network as we don't have anti-virus central management .

So , I found out the registry key that has the version and I wrote a script to read that version and "echo" the results into a shared .csv file. I executed this scripts remotely using microsoft pstools. I had a complete spread sheet by the end of the day .

How ever in your situation , there are many free software inventory applications that you can use to generate a report like this ( for IE version and service pack version) . so why you are going through scripting trouble ?
0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36709860
thanks jawa29!

I ran the script and the script sends the email to me perfectly.

however, will this script report on exception?

i.e. if a workstation has anything DIFFERENT to IE8 and SP3 - I want to receive an alert - if the workstation has IE8 and SP3 i do not want to receive an alert.

Perhaps another way to do this is to have the script append it's results to a spreadsheet / list which is held on the server somewhere?

Help !
0
 
LVL 8

Expert Comment

by:jawa29
ID: 36709890
Hi Rich

The script is constructed to only send an alert if the PC doesn't have IE version starting with 8 and SP version that doesn't start with 3.

Remember if you uncommented line 43 this will send an email regardless of the above, best to delete that line when you deploy via Machine Startup script.

Jawa29
0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36710022
OK jawa29 that works perfectly.

We have a slight problem with this in that I was going to send the SMTP alerts from the workstations to an SMTP relay on the same network but I've only just discovered that we can't get to this SMTP relay!

Is there any way we can send these results to a central server (file etc) and then monitor that file for anything different (different to IE8 and SP3) being reported by any of the workstations and then get the server to email us if it spots anything different in this file?

I know this is a big ask and I will give you the points regardless but it saves me having to ask another question !

Rich.
0
 
LVL 8

Expert Comment

by:jawa29
ID: 36710208
Ok Rich try this out.

This code to be ran on the client PC through a Machine Startup Script.
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2

On Error Resume Next

' Get local hostname
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set wmiColl = oWMIService.ExecQuery("Select * FROM Win32_ComputerSystem")
For Each wmiobj In wmiColl
	sHostName = UCase(wmiobj.Name)
Next

'Set the Registry Path to the Version key for IE
sKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
sValueName = "Version"

'Check registry for IE Version
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue

If Left(sValue, 1) <> "8" Then
	sErr = 1
	sText = "Internet Explorer version " & sValue
End If

' Get Service Pack level
Set colOSes = oWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
	sOS = objOS.Caption
	sSP = objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
Next

If Left(sSP, 1) <> "3" Then
	sErr = 1
	sText = sText & "Service Pack Version " & sOS & " " & sSP
End If

'If one of the values was wrong then create text file with results
If sErr = 1 Then

	If Right(sServerShare, 1) <> "\" Then
		sServerShare = sServerShare & "\"
	End If
	
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set oTextFile = oFSO.OpenTextFile(sServerShare & sHostName & ".txt", ForWriting, True)
	oTextFile.WriteLine(sText)
	oTextFile.Close	

End If

Open in new window

0
 
LVL 8

Expert Comment

by:jawa29
ID: 36710225
and this code to be ran on the server to email results and delete files once successful

Jawa29
Const ForReading = 1

On Error Resume Next

sFolderToCheck = "C:\pathtotextfiles\"
sFromAddress = "someone@domain.com"
sToAddress = "someone@domain.com"
sEMailServer = "smtpserver"
sEMailPort = 25

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolderToCheck)
Set oFiles = oFolder.Files

For Each File In oFiles

	Set oFile = oFSO.GetFile(File.Path)
	
	sHostName = Split(oFile.Name, ".")(0)
	
	Set oTextFile = oFSO.OpenTextFile(oFile.Path, ForReading, True)
	sText = oFile.ReadAll
	oFile.Close
	
	Set oEmail = CreateObject("CDO.Message")
	
	oEmail.From = sFromAddress
	oEmail.To = sToAddress
	oEmail.Subject = "IE Version & SP Version Report for " & sHostName
	oEmail.Textbody = sText
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sEMailServer
	oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sEMailPort
	oEmail.Configuration.Fields.Update
	oEmail.Send
	
	If Err.Number = 0 Then
		oFSO.DeleteFile oFile.Path, True
	End If
	Set oEmail = Nothing
	
Next

Open in new window

0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36716439
Hi jawa29

Those scripts look great - but we have a slight problem.  When we checked some of the PC's that the script shows us as only having IE6 installed they have IE8 iinstalled!

The script is right most of the time (90%) but obviously this is a troubling development.

Basically the script identified 3 machines here and 1 in a different site that all have IE6 (and thus need IE8 installed) and I've checked 2 of the 3 PC's here and they both have IE8 installed (and not IE6 as the script suggested).  The machine at the other site does have IE6 though so that is OK.

I know your script checks for the presence of a registry entry and I checked that and that shows 6.0.XXX so it's not your script that's wrong (it's the registry entry showing IE6 not IE8).

Weird or what?!

Can you help?

0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36716445
I forgot to mention - if you want the 500 points for this and we can open a new question (as this is a lot more work than I realised) then please just let me know - thanks.
0
 
LVL 8

Expert Comment

by:jawa29
ID: 36716488
Hi Rich

The ones reporting IE6 are they x64 systems?

Jawa29
0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36716533
Nope, I'm pretty sure they are all 32 bit (I don't think we have any 64-bit versions of Windows XP in our domain) ...
0
 
LVL 8

Accepted Solution

by:
jawa29 earned 500 total points
ID: 36716589
I can't explain why you would be getting this issue it could be any number of random things... I would however suggest re-installing IE8 on one of the machine and running the script against it afterwards, it could be a simple mis-install on IE's part.

Post back the results I'd be interested.

Jawa29
0
 
LVL 2

Author Comment

by:richardstuartpowell
ID: 36716669
OK jawa29, no worries ...

Your scripts delivered so full points to you mate :-)
0
 
LVL 2

Author Closing Comment

by:richardstuartpowell
ID: 37105938
thanks
0

Join & Write a Comment

Suggested Solutions

Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
Learn about cloud computing and its benefits for small business owners.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

743 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

13 Experts available now in Live!

Get 1:1 Help Now