Google Answers Logo
View Question
 
Q: Windows Address Book ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Windows Address Book
Category: Computers > Programming
Asked by: den2002-ga
List Price: $10.00
Posted: 30 Dec 2002 07:31 PST
Expires: 29 Jan 2003 07:31 PST
Question ID: 134927
HELP!
I have 35+ computers out in the field that i need to remotely modify
or at worst case, replace the address book.  I want to do this with a
routine that the user at the office can call themselves.  If this can
be done with a VBS script that i can send them, then that would be
great.

Several high ranking firings have left address in the address book
that need to be taken out.  I would rather do this without destroying
the whole address book, but whatever works.

To recap - I want to modify my users Windows Address Books without
having to dial into each individual machine and do it by hand. 
Suggestions?

Request for Question Clarification by cerebrate-ga on 30 Dec 2002 12:35 PST
Could you clarify whether you are using the Windows Address Book on
its own, or an e-mail application such as Microsoft Outlook
(presumably without Exchange)? If so, which e-mail application are you
using?

Thanks,

cerebrate-ga

Clarification of Question by den2002-ga on 30 Dec 2002 12:51 PST
Thanks for the quick response.

The remote computer are using Windows NT as an operating system, and
the email client is OUTLOOK 97.  The Windows Address Book is the one
that needs fixing.  Now, i'm not the guy who normally handles these
machines - he's on vacation - but i do kow that their are two sign ins
to the computers, but i don't think that that affects the address book
at all.  The users do not have administration rights to the computers,
but if it comes to it, we can execute whatever fix we come up with via
PCAnywhere - it should still be quicker than going into each machine
and changing the address book individually by hand.

If you need any more clarification, let me know.
Answer  
Subject: Re: Windows Address Book
Answered By: cerebrate-ga on 30 Dec 2002 16:22 PST
Rated:5 out of 5 stars
 
Dear den2002-ga,

Sorry for the delay in getting back to you. Information on accessing
the Windows Address Book from VBscript is surprisingly hard to come
by, which unfortunately turns out to be because the WAB itself *can't*
be accessed from script:

"There is a Win32 API for the Windows Address Book, but no COM
automation interface.  You would need to write your own COM wrapper."
 - Michael Harris (MVP) in
   http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&selm=u7TT4URyBHA.2200%40tkmsftngp02

I've confirmed this by referring to the relevant MSDN documentation.

However, all is not lost. As you're using Outlook, I would expect that
your addresses are stored in its "Contacts" folder, which in turn
passes the job of storing the e-mail addresses down to the WAB, and in
this case, altering the stored details in Outlook also affects the
WAB.

I've provided script samples to alter the address book in Outlook
here, they should be reasonably self-explanatory:

Adding a contact:

' Starts Outlook
Set myOlApp = CreateObject ("Outlook.Application")

' Creates a contact; repeat as necessary
' Other properties than these are available in Outlook help.
Set objNewContact = myOlApp.CreateItem (2) 'olContactItem
With objNewContact
  .FirstName = "Joe"
  .LastName = "User"
  .CompanyName = "Acme Inc."
  .Email1Address = "juser@acme.com"
  .Save
End With

Editing a contact:

' Starts Outlook and gets the contacts folder
Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
    myNameSpace.GetDefaultFolder(10) ' olFolderContacts

' Edits the contact; repeat as many times as necessary
Set objContact = myFolder.Items ("Joe User")
' full name is the default property, so we find by that
With objContact
  .Email1Address = "joeu@acme.com"
  .Save
End With

Deleting a contact:

' Starts Outlook and gets the contacts folder
Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
    myNameSpace.GetDefaultFolder(10) ' olFolderContacts

' Deletes the contact, repeat as many times as necessary
Set objContact = myFolder.Items ("Joe User")
' full name is the default property, so we find by that
objContact.Delete

A full list of the properties which you can use to create and edit
contacts is available in Microsoft Outlook Help.

Additional Links:

"Automating Microsoft Outlook Using Visual Basic Scripting Edition or
Visual Basic for Applications", MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnout98/html/msdn_ouvbsvba.asp

I'll add that I've only been able to double-check these scripts
against Outlook XP, which is all I have here, but from the
documentation I believe they should work fine on Outlook 97.

If these fail to meet your requirements and you need to access the WAB
itself directly, it would be possible to develop a small program to do
this for you; however, that would probably be getting beyond the scope
of this question at this point.

If this answer isn't quite what you're looking for, please feel free 
to request a clarification. 
  
Hope this helps,  
  
cerebrate-ga

Request for Answer Clarification by den2002-ga on 31 Dec 2002 05:59 PST
Thanks very much for the quick answer.  I'll go ahead and rate it now,
but could i trouble you for one more sample?  I just want to be able
to verify that an address is present in the address book.  Some of our
users have brains and probably added the new people without being told
to, but most of them probably didnt.  if you can tell me how to check
if an address has been added, then that would help me a lot.

Thank you again for the help you have given me.

Clarification of Answer by cerebrate-ga on 31 Dec 2002 07:50 PST
Certainly I can do that. To check whether a contact exists is most
easily done by looking up that contact and catching the error if it
doesn't exist - for large address books, this is much faster than
walking through all of them - as in the following script:

' Start Outlook and get the Contacts folder
Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = _
    myNameSpace.GetDefaultFolder(10) ' olFolderContacts

'If an error occurs in the next statement, then the item is not found
On Error Resume Next
Set objContact = myFolder.Items ("Joe User")
' full name is the default property, so we find by that

If Err.Number <> 0 Then
  If Err.Number = &H8004010F Then	' object could not be found
    MsgBox "Contact does not exist."
  Else
    MsgBox "Unrecognised error: " & Err.Number
  End If
End if

Err.Clear
On Error GoTo 0

In this script, I've just displayed a message box if the contact isn't
found. You don't say how you'd want to communicate this information
back if you're doing it remotely, but for your convenience I've
included a link to a page that, at the bottom, includes the VBScript
for e-mailing a message using both CDO (Outlook) and CDONTS (native
for Windows 2000 and above).

Hope this helps, and thank you for the complimentary comments,

cerebrate-ga

Additional Links:

"Handling VBScript Run-Time Errors", MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deconhandlingvbscriptruntimeerrors.asp

"Sending E-mail in VBS (SMTP)", ExpertsExchange
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11016941.html

Request for Answer Clarification by den2002-ga on 25 Mar 2003 08:03 PST
a while ago you helped me out with cleaning my address book.  The code
you supplied me with worked a treat in all the machines i tested it on
here. When i released it out into the field, it worked , but when the
user clicks on the 'to' button when they're sending an email, they
dont see all the address.  Have you any idea's as to what happened, or
can you explain to me the difference between the contacts list and the
address book.  If you dont have time i understand - this question was
closed a long time ago!

Thanks in advance,
Den
den2002-ga rated this answer:5 out of 5 stars
cerebrate-ga was more than helpful.  It's great researchers such as
him that is making Google answers so good.  Thanks again!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy