What if We Will Automate it Further?

As said, semi-automatic mode is better than nothing. But still, I guess, you’ll agree here, it’s not the way we should choose if we want to achieve productivity. We need the higher level of automation. Plus we want to be as more abstracted from the user side as it possible. As we are working in Active Directory environment it is reasonable to use its abilities and retrieve the information right from the active directory database. Going that way we’ll solve two problems at once: we will free ourselves from the need to fill in info personally user-by-user and strictly assign the signature to the user according to the official information stored in the Active Directory database. That allows avoiding confusion for the user and for the customer that will contact our user.

The Approach: Querying Active Directory for an Info

As we always do when we start working with some entities, we create an object instance that will represent it. Out main goal here is to retrieve information about the user, the member of the database, and then put it down into our document. We will use ADSystemInfo object and create its instance named objSysInfo that we will us to retrieve the system info data:

Set objSysInfo = CreateObject(“ADSystemInfo”)

After that we can retrieve a distinguished name of the user that is logged on to domain and that we want to create a signature for:

strUser = objSysInfo.UserName

We are using here the UserName property that is who returns the name of the user.

Username retrieved, we can connect (bind the object) to that user account. We use GetObject method that will create a new object from the reference we are linking it to:

Set objUser = GetObject(“LDAP://” & strUser)

Note: We can also shorten the expression and just write Set objUser = GetObject(“LDAP://” & objSysInfo.UserName). Then surely we have no need to define the strUser variable.

Getting the Stuff in Our Hands

That’s the time to start working with properties. What we need them for? We need them exactly to retrieve specific information that we will use during the document filling operation.

Typically a pair that will retrieve is the full user name and the company name and is well enough to build the signature. So basically we can limit the set of information that we will retrieve to just to properties:

1. FullName, this property will return the full name of the user. That is that the name that the user would basically get in the header of the Start menu if he will click on the Start button.

Note: If you haven’t add it, open Active Directory Users and Computers snap-in and change it. See this article for an additional info.

By the way there’s a nice article describing how to make this automatically using VBScript: How to change the display names of Active Directory users with Active Directory Services Interface script

2. Company, this property will return the full name of the company.

To call them just use this form

strName = objectname.property name

Thus to retrieve the user full name, use the following expression:

strName = objUser.FullName

Correspondingly, to retrieve user company name use the expression:

strCompany = objUser.Company

Note: In fact you can overview get all off them with your own eyes if you’ll select user properties in either your contacts or using the user properties smart-tag.

Here’s how to do that:

1. Create a new e-mail.
2. Enter User Name that is recorded in Active Directory
3. Point to the typed name. The user properties smart-tag will arise in the upper left corner on the user name
4. Click on the smart-tag and select Outlook Properties
5. All these properties will be listed on the General tab of the %username% Properties dialog box

Thus you now have a clue on how to enhance the representativeness of the user mail signature. Just use the properties listed there and add them after the name of the object you used to create connection.

Thus to add user telephone number to the user signature use this expression:

strPhone = objUser.telephoneNumber

How to program Outlook
Automatic Management of Signatures Bindings and Formatting
Windows Scripting Host (WSH) Properties List
User Class Properties Reference for Windows 2000 Server and Windows Server 2003 Active Directory Schema
IADsUser Interface Property List
Reading Active Directory Object Properties in C#
Defining Object Properties of any Active Directory Schema Interface object using IADs Interface
User Object Attributes
Sue Moshers’ Solution to Create Outlook Signature using Windows Management Instrumentation (WMI) scripting

Technorati:

Advertisements

Now that we’ll go further with this. How to push these settings enterprise-wide.

As we added line break to the document, we can continue to fill the signature and put (a last!) the name of the company we work in. The procedure is absolutely the same except that for now we are typing company name and hence we are passing the that out mysterious company ACME Corporation name to the input of the method:

objSelection.TypeText “ACME Corporation”

After that we are running Range() to end with the typed text selection block.

Now when we created the content of the signature we are stepping in to create the signature in Outlook. First off we need to create the object that will represent the parent of the object representing the signature. That means we should create objEmailOptions object:

Set objEmailOptions = objWord.EmailOptions

Alright, the parent is created, lets create the child, the objSignatureObject object:

Set objSignatureObject = objEmailOptions.EmailSignature

Now when we created the objSignatureObject signature object that’s the time to include our signature to the list of signatures. What’s the list? It’s the collection. Want to know how it looks like?

1. Open Outlook
2. Open Tools|Options and switch to the Mail Format tab on the Options dialog box
3. In the Signatures section click Signatures button to open the Create Signature dialog box
4. Here we are. The collection is just the list of items listed in the Signature list in this dialog

To create the collection we need to create object

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

We are ready to fill in the list now. To do that we need to add new item to the collection by using the Add method. To name it somehow we’ll just pass Standard Signature as the parameter:

objSignatureEntries.Add “Standard Signature”, objSelection

Let’s check what we created. Open the Create Signature dialog box as stated in the list above (see step 3) and check the Standard Signature is in the list of available signatures (or the only existing one if you haven’t created the single one yet).

“Wait, wait, wait, wait!” I hear you are saying that. “You told us about the name of the signature, but how did we create it?” You are right. We used reference to the created objSelection object to fill in the signature with the text. That’s what we used Word for.

OK. Signature is created, we can go. Unfortunately, not yet. You are asking, why? Look at the Signature section on the Mail Format tab in the Options dialog box. Observe two drop-down lists there. We haven’t assigned the signature yet. We need to make sure that when the user will either create or reply to the message the created signature will be used there. To do that we need to use two corresponding properties.

1. NewMessageSignature property is used to attach new signature to all newly created messages
2. ReplyMessageSignature property will be used in case user will reply to the incoming message

Lets go. As always, we are creating two objects:

objSignatureObject.NewMessageSignature = “Standard Signature”

objSignatureObject.ReplyMessageSignature = “Standard Signature”

Now look at the mentioned drop-down lists. The “Standard Signature” item is there and successfully selected. Try to create new mail or reply to the message. You will get the created signature attached at the bottom of your message.

By the way, if we would have another signature in the list of signatures we could set another one as the default either for new message or for the replied one depending on what you want it to be by typing its name within the quotes.

Voila! We ended with signature creation. That wasn’t too complicated tasks but still… Look at what we did? Can we leave this alone? Can we consider it to be the right solution? Of course, not. First of all we are talking about corporate environment with computers joined to domain. If we will stop with this solution it would require us either create a set of unique signature scripts, or create a huge IF branching that would put different names for signatures to make them unique for all user computers.

I’ll continue describing what we can do. For now you can find the ways right in the list of the articles I put at the bottom of this my note. See you later.

MSDN Magazine Scripting Outlook Signature article
How about automation? Automatic E-mail Signatures Creation
How to find and use Office object model documentation
Programming the Outlook object model
Microsoft Word Object Model
The TypeText Method
Microsoft Word Selection Object Members
What’s new in Outlook 2007 Object Model

Technorati tags:

Introduction

The steps to create mail signature in Outlook manually are not so complex to perform. But as it usually happens, this ‘rule’ cannot be applied to all cases. Once you can burden this task on user’s shoulders in a small company with a few computers in net and probably no Active Directory, go do it in large company. Even in relatively large company it’s nearly impossible to force users to go beyond corporate rules on formatting the signature. At any time in any place chances are very high we will get the chaos within the settings of users’ signatures. Ones just will be unable to create them at all, others will leave your direction and not set signature at all, while the rest will edit the standardized formatting to what they like to look like and… You will get the chaos. Imagine you will start labeling your corporate logo differently each time you put it somewhere. John will put it that like, Marianne will add some flowers at the very left conner of the logo because she is delighted with the Spring that came earlier (later?) this year. Absurd? For sure. Logo is that kind of things that usually changes only by common agreement and cannot change and depend on the each single person wish. Surely, you can create legal notices, you can stick banners screaming on users and forcing them to comply the rules. But the question is: should you do that? Or to say it better: should THEY do it? At least they were employed to do what they are specializing in and what they can do best, so why bothering them with excess problems and drawing them away from their internal responsibilities. While there are things that people should be able to freely made themselves, there are things at the same time that must be standardized. Just for the sake of following corporate rules, for the sake of what any standards are created for.

First Steps to Automate Creation of Outlook Signature

Here I will go through the process describing the process of how to create e-mail signature for Outlook using automation in the step-by-step manner.

The first thing you start thinking about automation is probably scripting. And because we want to add text here, we need to use Microsoft Office Word. Moreover, Outlook object model as it seemingly seems does not include methods that would allow to create and assign signatures for e-mail messages.

Semi-Automatic Approach

First of all we need to open our application. Because we will use Word here, we need to start Word application.

Set objWord = CreateObject(“Word.Application”)

We are creating objWord object to do that. If we want our application to be visible as we start it allowing the user to see the main application window, we need to set object property accordingly. Thus we can set Visible property of objWord instance to true.

‘objWord.Visible = True

Uncomment the string in the script and you’ll see the window displayed without any document opened in it. Comment it back on and you’ll see only the process instance displayed within the list of your task manager. But aren’t we here to create the signature? To create it we need to create a document that we will fill in further with signature info. To create a new document we need to use Add method and create a objDoc object which will designate the document we are creating:

Set objDoc = objWord.Documents.Add()

Alright. We created the document. Let’s start righting the text. We need some method that will do the job for us. Something like TypeText would be able to do that job for us. But the objWord object doesn’t have such a method contained within its object model. What should we do? Right what we do when we start typing out document. We should put an insertion point within it. What cannot be done with one object can be done with another one. The first thing that Scripting Guys are suggesting to use to type e-mail signature in live is to create Word’s Selection object. Here’s how we do that:

Set objSelection = objWord.Selection

Now we can start writing our first string of text to build the signature. We need to invoke the mentioned TypeText method here:

objDoc.TypeText “FirstName LastName”

Where the FirstName and the LastName strings are placeholders for the text that will be typed in the document. Thus if you will put John Doe here, and run the TypeText method you will see the John Doe string written in the first row of the Microsoft Word document. Now then we usually type the company name under the personal name. Okay, let’s write the name of the company. Let it be the mysterious ACME Corporation:

objDoc.TypeText “FirstName LastName”

But wait, why we got out strings sticked one to each other? That’s because we forgot to do out second action we do when we type the documents, breaking the line and inserting line feed and caret return to it. That is we need to put here our well-known “Press ENTER to continue”. What’s Enter in Word? It is paragraph. Strictly speaking paragraph is more complex thing in Word because it holds style and formatting info, but let cut its capabilities to such a limited scope. To put the paragraph we should add this

objSelection.TypeParagraph()

line to the code.

You can find the whole article here
Extra info on scripts utilizing XML and HTA can be found here
Script Automation: Automatic Genereation of E-mail Signatures on User Side Without User Intervention
How to find and use Office object model documentation
Programming the Outlook object model

Technorati tags:

When I was talking about the trick to update the in-use file with new version the last step to say good-bye to the current session and start working with the updated version was to reboot the PC. Quite reasonable one would ask if it’s possible to automate this process too? Yes, we can reboot the PC automatically using shutdown utility that come with Windows distribution and is locate in the %systemroot%\system32\ folder. To automate the reboot procedure we need to pass -r switch to input of the shutdown.exe tool
shutdown -r [-f]
By the way, notice the [-f] parameter I put in the command line in addition to the -r parameter. It is an additional parameter used to force computer shutdown and force closing of running tasks. Use this switch carefully as you will lose data that hasn’t been saved before running the reboot.