'Klaus Seeling, Voith, 2000-08-21, v1.0, , +49 7321 37 3042
Const MHSCommonName = &H3A0F001E
Const Addresses = &H800F101E
Select Case UCase(Right(WScript.FullName, 11))
Case "WSCRIPT.EXE"
 Engine = "W"
Case "CSCRIPT.EXE"
 Engine = "C"
End Select
If WScript.Arguments.Count <> 3 Then
 DisplayHelp
Else
 MapiProfile = WScript.Arguments.Item(0)
 Mode = UCase(WScript.Arguments.Item(1))
 Value = UCase(WScript.Arguments.Item(2))
 Set MapiSession = CreateObject("MAPI.Session")
 MapiSession.Logon MapiProfile, "", False
 Set Gal = MapiSession.AddressLists.Item(1)
 Set GalAddressEntries = Gal.AddressEntries
 ObjectNotFound = True
 Select Case Mode
 Case "D"
  Set GalAddressEntriesFilter = GalAddressEntries.Filter
  GalAddressEntriesFilter.Fields.Add MHSCommonName, Value
  If GalAddressEntries.Count > 0 Then
   For i = 1 To GalAddressEntries.Count
    If UCase(GalAddressEntries.Item(i).Fields.Item(MHSCommonName)) = Value Then
     ObjectNotFound = False
     If Engine = "W" Then
      MsgBox "Object found: " & GalAddressEntries.Item(i).Name, vbOKOnly, "Found"
     Else
      WScript.StdOut.WriteLine "Object found: " & GalAddressEntries.Item(i).Name
     End If
    End If
   Next
   If ObjectNotFound Then
    If Engine = "W" Then
     MsgBox "Object not found!", vbCritical, "Not Found"
    Else
     WScript.StdOut.WriteLine "Object not found!"
    End If
   End If
  Else
   If Engine = "W" Then
    MsgBox "Object not found!", vbCritical, "Not Found"
   Else
    WScript.StdOut.WriteLine "Object not found!"
   End If
  End If
 Case "A"
  For i = 1 To GalAddressEntries.Count
   On Error Resume Next
   AllAddresses = GalAddressEntries.Item(i).Fields.Item(Addresses)
   If Err.Number = 0 Then
    For j = 1 to UBound(AllAddresses)
     If UCase(AllAddresses(j)) = Value Then
      ObjectNotFound = False
      If Engine = "W" Then
       MsgBox "Object found: " & GalAddressEntries.Item(i).Name, vbOKOnly, "Found"
      Else
       WScript.StdOut.WriteLine "Object found: " & GalAddressEntries.Item(i).Name
      End If
     End If
    Next
   End If
  Next
  If ObjectNotFound Then
   If Engine = "W" Then
    MsgBox "Object not found!", vbCritical, "Not Found"
   Else
    WScript.StdOut.WriteLine "Object not found!"
   End If
  End If
 Case "P"
  For i = 1 To GalAddressEntries.Count
   On Error Resume Next
   AllAddresses = GalAddressEntries.Item(i).Fields.Item(Addresses)
   If Err.Number = 0 Then
    For j = 1 to UBound(AllAddresses)
     If Left(AllAddresses(j), 1) = UCase(Left(AllAddresses(j),1)) Then
      If UCase(AllAddresses(j)) = Value Then
       ObjectNotFound = False
       If Engine = "W" Then
        MsgBox "Object found: " & GalAddressEntries.Item(i).Name, vbOKOnly, "Found"
       Else
        WScript.StdOut.WriteLine "Object found: " & GalAddressEntries.Item(i).Name
       End If
      End If
     End If
    Next
   End If
  Next
  If ObjectNotFound Then
   If Engine = "W" Then
    MsgBox "Object not found!", vbCritical, "Not Found"
   Else
    WScript.StdOut.WriteLine "Object not found!"
   End If
  End If
 Case Else
  DisplayHelp
 End Select
End If

Sub DisplayHelp()
 If Engine = "W" Then
  MsgBox "Search:" & vbCRLF &_
         "   Search for properties M$ doesn't provide" & vbCRLF & vbCRLF &_
         "Usage: Search   " & vbCRLF &_
         "   Modi:"  & vbCRLF &_
         "      D = Directory Name" & vbCRLF &_
         "      A = Address (eg. SMTP:)" & vbCRLF &_
         "      P = Primary Address only", vbOKOnly, "Search Item"
 Else
  WScript.StdOut.WriteLine "Search:"
  WScript.StdOut.WriteLine " Search for properties M$ doesn't provide" & vbCRLF
  WScript.StdOut.WriteLine "Usage: Search   "
  WScript.StdOut.WriteLine " Modi:"
  WScript.StdOut.WriteLine "  D = Directory Name"
  WScript.StdOut.WriteLine "  A = Address (eg. SMTP:)"
  WScript.StdOut.WriteLine "  P = Primary Address only"
 End If
End Sub
This page was last updated on May 01, 2006 04:28 PM.