Solved

VB Script Error 0x80005000

Posted on 2009-05-05
2
975 Views
Last Modified: 2012-05-06
I found a VB Script over at WindowsITPro (InstantDoc #46819) for sending password expiration emails. The script seems to work (users get the proper email notifications) but at the end of the script I get an error:
"reportpasswordchange.vbs(56, 3) (null): 0x80005000"

Also, when the email is actually sent, there is no "sender name" in the email. Where am I going wrong?
'

' John Savill 8th June 2005

' Runs check on last password change date

'

Option Explicit
 

Dim objCommand, objConnection, objChild, objUserConnection, strBase, strFilter, strAttributes, strPasswordChangeDate, intPassAge

Dim lngTZBias, objPwdLastSet, strEmailAddress, objMessage

Dim objShell, lngBiasKey, k, PasswordExpiry, strRootDomain

Dim strQuery, objRecordset, strName, strCN
 

' ********************* CHANGE THESE VALUES TO PASSWORD EXPIRY AND ROOT OF WHERE USERS WILL BE SEARCHED ***********************************
 

PasswordExpiry=42

strRootDomain="dc=domain,dc=local"
 

' *****************************************************************************************************************************************
 
 

' Obtain local Time Zone bias from machine registry.

Set objShell = CreateObject("Wscript.Shell")

lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")

If UCase(TypeName(lngBiasKey)) = "LONG" Then

  lngTZBias = lngBiasKey

ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then

  lngTZBias = 0

  For k = 0 To UBound(lngBiasKey)

    lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)

  Next

End If
 

Set objCommand = CreateObject("ADODB.Command")

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

objCommand.ActiveConnection = objConnection

strBase = "<LDAP://" & strRootDomain & ">"
 

strFilter = "(&(objectCategory=person)(objectClass=user))"

strAttributes = "sAMAccountName,cn,mail,pwdLastSet,distinguishedName"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

objCommand.CommandText = strQuery

objCommand.Properties("Page Size") = 100

objCommand.Properties("Timeout") = 30

objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute
 

' WScript.echo "Running at " & Date()
 

Do Until objRecordSet.EOF

  strName = objRecordSet.Fields("sAMAccountName").Value

  strCN = objRecordSet.Fields("cn").value

  strEmailAddress = objRecordSet.Fields("mail").value

  Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN
 

  Set objUserConnection = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)

  Set objPwdLastSet = objUserConnection.pwdLastSet

  strPasswordChangeDate = Integer8Date(objPwdLastSet, lngTZBias)

  WScript.Echo vbTab & "Password last changed at " & strPasswordChangeDate

  intPassAge = DateDiff("d", strPasswordChangeDate, Now)

  WScript.Echo vbTab & "Password changed " & intPassAge & " days ago"
 

  If intPassAge = (PasswordExpiry-3) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 3 days"

    Call SendEmailMessage(strEmailAddress, 3)

  ElseIf intPassAge = (PasswordExpiry-6) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 6 days"

    Call SendEmailMessage(strEmailAddress, 6)

  ElseIf intPassAge = (PasswordExpiry-9) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 9 days"

    Call SendEmailMessage(strEmailAddress, 9)

  End If
 

  objRecordSet.MoveNext

Loop
 

objConnection.Close
 
 

Function Integer8Date(objDate, lngBias)

' Function to convert Integer8 (64-bit) value to a date, adjusted for

' local time zone bias.

  Dim lngAdjust, lngDate, lngHigh, lngLow

  lngAdjust = lngBias

  lngHigh = objDate.HighPart

  lngLow = objdate.LowPart

  ' Account for error in IADslargeInteger property methods.

  If lngLow < 0 Then

    lngHigh = lngHigh + 1

  End If

  If (lngHigh = 0) And (lngLow = 0) Then

    lngAdjust = 0

  End If

  lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _

  + lngLow) / 600000000 - lngAdjust) / 1440

' Trap error if lngDate is overly large

  On Error Resume Next

  Integer8Date = CDate(lngDate)

  If Err.Number <> 0 Then

    On Error GoTo 0

    Integer8Date = #1/1/1601#

  End If

  On Error GoTo 0

End Function
 

Sub SendEmailMessage(strDestEmail, strNoOfDays)

  Set objMessage = CreateObject("CDO.Message") 

  objMessage.Subject = "Reminder: Your Password Expires in " & strNoOfDays & " days" 

  objMessage.Sender = "notification@domain.local"

  objMessage.To = strDestEmail 

  objMessage.Importance = CdoHigh

  objMessage.TextBody = "Your password expires in " & strNoOfDays & " days." 

  objMessage.Send

End Sub

Open in new window

0
Comment
Question by:DVation191
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
zoofan earned 500 total points
ID: 24306596
Try this,

I changed line 50 to Do while NOT EOF

and added line 110 message.from


zf
'

' John Savill 8th June 2005

' Runs check on last password change date

'

Option Explicit

 

Dim objCommand, objConnection, objChild, objUserConnection, strBase, strFilter, strAttributes, strPasswordChangeDate, intPassAge

Dim lngTZBias, objPwdLastSet, strEmailAddress, objMessage

Dim objShell, lngBiasKey, k, PasswordExpiry, strRootDomain

Dim strQuery, objRecordset, strName, strCN

 

' ********************* CHANGE THESE VALUES TO PASSWORD EXPIRY AND ROOT OF WHERE USERS WILL BE SEARCHED ***********************************

 

PasswordExpiry=42

strRootDomain="dc=domain,dc=local"

 

' *****************************************************************************************************************************************

 

 

' Obtain local Time Zone bias from machine registry.

Set objShell = CreateObject("Wscript.Shell")

lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")

If UCase(TypeName(lngBiasKey)) = "LONG" Then

  lngTZBias = lngBiasKey

ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then

  lngTZBias = 0

  For k = 0 To UBound(lngBiasKey)

    lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)

  Next

End If

 

Set objCommand = CreateObject("ADODB.Command")

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

objCommand.ActiveConnection = objConnection

strBase = "<LDAP://" & strRootDomain & ">"

 

strFilter = "(&(objectCategory=person)(objectClass=user))"

strAttributes = "sAMAccountName,cn,mail,pwdLastSet,distinguishedName"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

objCommand.CommandText = strQuery

objCommand.Properties("Page Size") = 100

objCommand.Properties("Timeout") = 30

objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

 

' WScript.echo "Running at " & Date()

 

Do While Not objRecordSet.EOF

  strName = objRecordSet.Fields("sAMAccountName").Value

  strCN = objRecordSet.Fields("cn").value

  strEmailAddress = objRecordSet.Fields("mail").value

  Wscript.Echo "NT Name: " & strName & ", Common Name: " & strCN

 

  Set objUserConnection = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)

  Set objPwdLastSet = objUserConnection.pwdLastSet

  strPasswordChangeDate = Integer8Date(objPwdLastSet, lngTZBias)

  WScript.Echo vbTab & "Password last changed at " & strPasswordChangeDate

  intPassAge = DateDiff("d", strPasswordChangeDate, Now)

  WScript.Echo vbTab & "Password changed " & intPassAge & " days ago"

 

  If intPassAge = (PasswordExpiry-3) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 3 days"

    Call SendEmailMessage(strEmailAddress, 3)

  ElseIf intPassAge = (PasswordExpiry-6) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 6 days"

    Call SendEmailMessage(strEmailAddress, 6)

  ElseIf intPassAge = (PasswordExpiry-9) Then

    WScript.echo vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 9 days"

    Call SendEmailMessage(strEmailAddress, 9)

  End If

 

  objRecordSet.MoveNext

Loop

 

objConnection.Close

 

 

Function Integer8Date(objDate, lngBias)

' Function to convert Integer8 (64-bit) value to a date, adjusted for

' local time zone bias.

  Dim lngAdjust, lngDate, lngHigh, lngLow

  lngAdjust = lngBias

  lngHigh = objDate.HighPart

  lngLow = objdate.LowPart

  ' Account for error in IADslargeInteger property methods.

  If lngLow < 0 Then

    lngHigh = lngHigh + 1

  End If

  If (lngHigh = 0) And (lngLow = 0) Then

    lngAdjust = 0

  End If

  lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _

  + lngLow) / 600000000 - lngAdjust) / 1440

' Trap error if lngDate is overly large

  On Error Resume Next

  Integer8Date = CDate(lngDate)

  If Err.Number <> 0 Then

    On Error GoTo 0

    Integer8Date = #1/1/1601#

  End If

  On Error GoTo 0

End Function

 

Sub SendEmailMessage(strDestEmail, strNoOfDays)

  Set objMessage = CreateObject("CDO.Message") 

  objMessage.Subject = "Reminder: Your Password Expires in " & strNoOfDays & " days" 

  objMessage.Sender = "notification@domain.local"

  objMessage.From = "notification@domain.local"

  objMessage.To = strDestEmail 

  objMessage.Importance = CdoHigh

  objMessage.TextBody = "Your password expires in " & strNoOfDays & " days." 

  objMessage.Send

End Sub

Open in new window

0
 
LVL 12

Expert Comment

by:zoofan
ID: 24307000
Glad I could help,  thanks for the points :-)



zf
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

19 Experts available now in Live!

Get 1:1 Help Now