Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with a VBScript

Posted on 2011-04-20
3
Medium Priority
?
272 Views
Last Modified: 2012-05-11
I have this script and I was wondering how I could make it so that when executed it would only send an email when the account was disabled and not when the account is already disabled.  See my plans are to have this ran everyday through a scheduler and i dont want to get an email every day if the account is already disabled.  I only want to know when it was disabled if it was previously enabled.
strUserDN = "CN=test,OU=Test Accounts,OU=Security,DC=inc,DC=com"
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.AccountDisabled = True
objUser.SetInfo

' Email variables:
strServer = "smtp.inc.com"
strTo = "test@test.com"
strFrom = "AcctControlAdmin@test.com"
strSubject = "Account was disabled."
strBody = "The Account was disabled." & VbCrLf

SendEmail strServer, strTo, strFrom, strSubject, strBody, ""

Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody, strAttachment)
        Dim objMessage
        
        Set objMessage = CreateObject("CDO.Message")
        objMessage.To = strTo
        objMessage.From = strFrom
        objMessage.Subject = strSubject
        objMessage.TextBody = strBody
  		If strAttachment <> "" Then objMessage.AddAttachment strAttachment
  		
        '==This section provides the configuration information for the remote SMTP server.
        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") = strServer
        '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
        Set objMessage = Nothing
End Sub

Open in new window

0
Comment
Question by:seaninman
3 Comments
 
LVL 17

Accepted Solution

by:
Tony Massa earned 1000 total points
ID: 35434560
Since you're disabling the account in the script, we'll just add a couple lines to notify ONLY when the account is enabled...otherwise, it's always supposed to be disabled.

 
strUserDN = "CN=test,OU=Test Accounts,OU=Security,DC=inc,DC=com"
Set objUser = GetObject("LDAP://" & strUserDN)

'Added Code ---------------------------
If objUser.AccountDisabled = True Then
	'Do Nothing
Else
'End Added Code -----------------------

  objUser.AccountDisabled = True
  objUser.SetInfo

  ' Email variables:
  strServer = "smtp.inc.com"
  strTo = "test@test.com"
  strFrom = "AcctControlAdmin@test.com"
  strSubject = "Account was disabled."
  strBody = "The Account was disabled." & VbCrLf

  SendEmail strServer, strTo, strFrom, strSubject, strBody, ""
End If
Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody, strAttachment)
        Dim objMessage
        
        Set objMessage = CreateObject("CDO.Message")
        objMessage.To = strTo
        objMessage.From = strFrom
        objMessage.Subject = strSubject
        objMessage.TextBody = strBody
  		If strAttachment <> "" Then objMessage.AddAttachment strAttachment
  		
        '==This section provides the configuration information for the remote SMTP server.
        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") = strServer
        '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
        Set objMessage = Nothing
End Sub

Open in new window

0
 
LVL 4

Author Comment

by:seaninman
ID: 35435300
Getting this error message after adding that... error
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 1000 total points
ID: 35474112
Did you copy the entire code above?  You should have the End Sub at the bottom of your code.

Rob.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

581 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